参考:https://blog.youkuaiyun.com/zhuswy/article/details/80267748
1.安装qrcode.js
npm install qrcodejs2 --save
2.页面中引入
import QRCode from 'qrcodejs2'
3.页面使用
<div id="qrcode" ref="qrcode"></div>
methods:{ qrcode () { let qrcode = new QRCode('qrcode', { width: 232, // 设置宽度 height: 232, // 设置高度 text: 'https://baidu.com' }) } } /* @ 在需要调用的地方 这样必须这样调用 否则会出现 appendChild null 就是id为qrcode的dom获取不到 返回结果为null */ this.$nextTick (function () { this.qrcode(); })
更简单直接的方法:
src = "http://qr.topscan.com/api.php?bg=ffffff&fg=000000&text=" + code; //code为券码
本文详细介绍了如何在项目中安装并使用qrcode.js库来生成二维码。从安装库到页面引入,再到具体使用方法,包括设置二维码的尺寸和内容,提供了完整的示例代码。同时,还提供了一种更简单的生成二维码图片链接的方法。
1150

被折叠的 条评论
为什么被折叠?



