"qrcodejs2": "^0.0.2",
"html2canvas": "^1.0.0-rc.3",
import QRCode from 'qrcodejs2'
import html2canvas from 'html2canvas';
<div id="cartcanvas" style="width: 136px;height: 136px;" v-if="share" @click="save"></div>
lookQRcode(url) {
this.share = true
this.$nextTick(() => {
this.useqrcode(url)
})
},
useqrcode(url1){ //生成二维码
let company_id = sessionStorage.getItem('company_id');
let institution_id = sessionStorage.getItem('institution_id');
let appcode = sessionStorage.getItem('appcode');
let url = url1;
let qrcode = new QRCode('cartcanvas', {
width: 136, //图像宽度
height: 136, //图像高度
typeNumber:4,
correctLevel : QRCode.CorrectLevel.H //容错级别 容错级别有:(1)QRCode.CorrectLevel.L (2)QRCode.CorrectLevel.M (3)QRCode.CorrectLevel.Q (4)QRCode.CorrectLevel.H
})
qrcode.makeCode(url) //生成另一个新的二维码
},
save() { //下载名片
var _this = this;
let ele = document.getElementById('cartcanvas')
html2canvas(ele).then(function(canvas) { //调用html2canvas把整个页面画下来
var imgUrl = canvas.toDataURL("image/jpeg"); //转换成url链接
let saveA = document.createElement("a"); //创建a链接下载
document.body.appendChild(saveA);
saveA.href = imgUrl;
saveA.download = _this.userName; //下载的文件名
saveA.target = "_blank";
saveA.click();
});
},
QRCode生成二维码,html2canvas下载图像
最新推荐文章于 2024-06-28 17:37:27 发布