keyeking

qrcode函数库用于生成二维码:https://www.npmjs.com/package/qrcode

安装

npm i qrcode

引包

import QRCode from \'qrcode\'
QRCode.toDataURL(\'I am a pony!\')
  .then(url => {
    console.log(url)
  })
  .catch(err => {
    console.error(err)
  })

这里toDataURL接收一个二维码的地址

let result=QRCode.toDataURL(‘....url’)
      console.log(result)

可以看到输出的这个result是一个promise对象

 

 但是这个要的不是这个promise,所以我们需要等待成功的回调

可以结合async和await使用

 

此时在返回的就是一个二维码的地址

 

分类:

技术点:

相关文章:

  • 2021-12-09
  • 2021-12-13
  • 2021-11-03
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-09
  • 2021-11-21
  • 2022-12-23
  • 2022-12-23
  • 2021-11-23
相关资源
相似解决方案