下载
npm install qrcodejs2 --save
导入
import QRCode from 'qrcodejs2' // 引入qrcode
页面使用
<div style="border:1px solid #ebebeb;width:222px;padding:10px">
<div id="qrcode" ref='qrcode'></div>
</div>
js代码
qrcode (url) { // 生成二维码
if (this.$refs.qrcode.childNodes.length != 0) {
this.$refs.qrcode.removeChild()
}
let qrcode = new QRCode('qrcode', {
width: 200,
height: 200,
text: url, // 二维码转换地址
colorDark: '#000',
colorLight: '#fff'
})
},