代码如下:
引入qrcode--------npm install qrcode <template> <div> <div id=‘code‘></div> <canvas id="canvas"></canvas> </div> </template> <script> import Vue from ‘vue‘ import QRCode from ‘qrcode‘ Vue.use(QRCode) export default { data() { return { codes: ‘‘ } }, methods: { useqrcode() { var canvas = document.getElementById(‘canvas‘) QRCode.toCanvas(canvas, ‘http://www.baidu.com‘, function(error) { if (error) console.error(error) console.log(‘success!‘); }) } }, mounted() { this.useqrcode(); } } </script> <style> #canvas { width: 200px !important; height: 200px !important; } </style>
原文地址:https://www.cnblogs.com/hool/p/12045574.html
时间: 2024-11-02 14:59:51