0
点赞
收藏
分享

微信扫一扫

QRCode.js生成二维码

人间四月天i 2022-03-14 阅读 64

一、安装
项目文件夹中执行

npm install --save qrcode
或者,全局安装

npm install -g qrcode

在ES6/ES7中使用

import QRCode from 'qrcode' 
// import引入可能会导致报错,可以尝试require
// const QRCode = require('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)
  }
}

使用

<img :src="erCodeImg"/>


data(){
return {
erCodeImg:""
}
}

createdFun(){
let url = "https://www.baidu.com/",
QRCode.toDataURL(url)
  .then(url => {
    console.log(url)
    this.erCodeImg = url
  })
  .catch(err => {
    console.error(err)
  })
}

举报

相关推荐

0 条评论