Blogger Information
Blog 87
fans 1
comment 0
visits 59154
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
vue二维码学习
阿杰
Original
756 people have browsed it

1、先引进qrcode.js

  1. import QRCode from 'qrcodejs2'

2、设置展示二维码的标签

  1. <div class="qrcode" id="qrcode"></div>

3、生成二维码的关键js

  1. // 生成二维码
  2. GetQRcode(){
  3. new QRCode('qrcode', {
  4. text: , // 需要生成二维码的内容
  5. width: 256,
  6. height: 256,
  7. colorDark : '#000000',
  8. colorLight : '#ffffff',
  9. correctLevel : QRCode.CorrectLevel.H //容错率,L/M/H
  10. });
  11. },

4、下载生成的二维码

  1. // 下载二维码
  2. downLoad(){
  3. var canvas = document.getElementById('qrcode').getElementsByTagName('canvas');
  4. this.downLoadImage(canvas);
  5. },
  6. downLoadImage(canvas){
  7. var a = document.createElement("a");
  8. a.href = canvas[0].toDataURL('image/png');
  9. a.download = this.form.oppor_name;
  10. a.click();
  11. a = null;
  12. },

5、特别注意

  • 动态生成多个二维码时,关掉某一个二维码时要清空展示二维码标签,否则canvas画布渲染会导致出现重复二维码
  • 如下:

  • 处理方法

  1. //关闭
  2. closeT(){
  3. // console.log('close');
  4. var codeHtml = document.getElementById('qrcode');
  5. codeHtml.innerHTML = "";
  6. this.$emit('closed')
  7. },
  • 处理完成后,正确显示

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post