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对象 将字符串转换为二维码