欢迎来到DIVCSS5查找CSS资料与学习DIV CSS布局技术!
1、安装
 
npm install qrcodejs2 --save
 
2、在页面中引入
 
import QRCode from 'qrcodejs2'
 
export default {
 
  components: { QRCode },
 
 }
 
3、页面使用
 
  <div class="ercode">
 
        <div class="bookcode" id="qrcode" ref="qrcode1"></div>
 
        <el-button @click="download" style="margin-top: 10px;">下载
 
        </el-button>
 
</div>
 
4、生成二维码
 
    qrcode () {
 
      let qrcode = new QRCode('qrcode', {
 
        width: 220, //图像宽度
 
        height: 220, //图像高度
 
        colorDark: '#000000', //前景色
 
        colorLight: '#ffffff', //背景色
 
        typeNumber: 4,
 
        correctLevel: QRCode.CorrectLevel.H
 
      });
 
      qrcode.clear(); //清除二维码
 
      qrcode.makeCode('需要转化的网址');
 
    },
 
5、下载图片
 
    download() {
 
      var qrcode = document.getElementById("qrcode");
 
      var img = qrcode.lastChild  // 获取img的dom节点
 
      const a = document.createElement('a') // 创建a标签
 
      a.href = img.src 
 
      a.setAttribute('download', '二维码') // 设置下载属性
 
      a.click()
 
    },

如需转载,请注明文章出处和来源网址:http://www.divcss5.com/html/h64197.shtml