Vue项目中使用qrcode生成二维码

1
yarn add qrcode
1
2
3
4
5
6
<template>
<div>
<div id='code'></div>
<canvas id="canvas"></canvas>
</div>
</template>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import QRCode from 'qrcode'

export default{
data(){
return {
code: ''
}
},
components: {
QRCode: QRCode
},
methods:{
useqrcode() {
var canvas = document.getElementById('canvas')
QRCode.toCanvas(canvas, 'http://www.appblog.cn', function (error) {
if (error) console.error(error)
console.log('success!');
})
}
},
mounted(){
this.useqrcode();
}
}

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2020 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :