vue项目中使用qrcode生成二维码
1、安装:npm install qrcode
2、html:
1 <template> 2 <div> 3 <div id="code"></div> 4 <canvas id="canvas"></canvas> 5 </div> 6 </template>
3、逻辑:
1 import QRCode from 'qrcode 2 export default { 3 data () { 4 return { codes: '' } 5 }, 6 components: { 7 QRCode 8 }, 9 methods: { 10 useqrcode () { 11 var canvas = document.getElementById('canvas') 12 QRCode.toCanvas(canvas, 'http://www.baidu.com', function (error) { 13 if (error) console.error(error) 14 console.log('success!') 15 }) 16 } 17 }, 18 mounted () { 19 this.useqrcode() 20 } 21 }