Vue中生成二维码 组件库qrcode使用

qrcode网址:

https://www.npmjs.com/package/qrcode

安装代码如下:

npm install qrcode
qrcode文档中生成二维码有很多环境下的用法。我们这里使用ES6/ES7的用法。

ES6/ES7
Promises and Async/Await can be used in place of callback function.

import QRCode from 'qrcode'

// With promises
QRCode.toDataURL('I am a pony!')
.then(url => {
console.log(url)
})
.catch(err => {
console.error(err)
})

// With async/await
const generateQR = async text => {
try {
console.log(await QRCode.toDataURL(text))
} catch (err) {
console.error(err)
}
}


 

 

图中是通过wx图片url的路径生成二维码 生成的是Promise对象 将字符串转换为二维码
————————————————
版权声明:本文为CSDN博主「编程界的冠希」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/m0_65262198/article/details/124079944

posted @ 2023-03-20 17:10  鼓舞飞扬  阅读(516)  评论(0)    收藏  举报