欢迎访问生活随笔!

生活随笔

您现在的位置是:首页 > 形式科学 > 计算机科学 > IT网络

IT网络

VUE生成二维码插件

发布时间:2022-11-11IT网络 小博士
原文:https://www.jianshu.com/p/496fd1cbee8d
npm安装qrcodejs2 -保存
页面介绍
Dom结构
JS方法编写
出口

原文:https://www.jianshu.com/p/496fd1cbee8d

npm install qrcodejs2 --save
页面中引入

dom 结构

JS 方法编写
export default {

data(){ link: 'https://baidu.com' }, methods: { // 生成二维码 qrcode () { let that = this; let qrcode = new QRCode('qrcode', { 124, height: 124, // 高度 text: this.link, // 二维码内容 // render: 'canvas' , // 设置渲染方式(有两种方式 table和canvas,默认是canvas) // background: '#f0f', // 背景色 // foreground: '#ff0' // 前景色 }) } }, components: { QRCode }

}

5)页面调用

// 注意: 在需要调用的地方 这样必须这样调用 否则会出现 appendChild null 就是id为qrcode的dom获取不到 返回结果为null

this.$nextTick (function () { this.qrcode(); })

2、vue-qart
1) 安装 vue-qart

npm install vue-qart --save
页面中引入

data 中数据配置

export default {

data(){ downloadButton:false, config: { value: 'https://baidu.com', imagePath: '/static/logo/logo.png', filter: 'color' } }, components: { VueQArt } }

dom 结构

3 实际项目中
3.1 引入文件
qrcodejs2---引入.jpg
3.2 生成二维码函数

生成二维码的函数.jpg
3.3 相应的位置调用函数