import QRCode from 'qrcodejs2'
<div class="qrcode" id="qrcode"></div>
// 生成二维码
GetQRcode(){
new QRCode('qrcode', {
text: , // 需要生成二维码的内容
width: 256,
height: 256,
colorDark : '#000000',
colorLight : '#ffffff',
correctLevel : QRCode.CorrectLevel.H //容错率,L/M/H
});
},
// 下载二维码
downLoad(){
var canvas = document.getElementById('qrcode').getElementsByTagName('canvas');
this.downLoadImage(canvas);
},
downLoadImage(canvas){
var a = document.createElement("a");
a.href = canvas[0].toDataURL('image/png');
a.download = this.form.oppor_name;
a.click();
a = null;
},
如下:
处理方法
//关闭
closeT(){
// console.log('close');
var codeHtml = document.getElementById('qrcode');
codeHtml.innerHTML = "";
this.$emit('closed')
},