qrcode生成二維碼(長按可複製,掃描)

<canvas id="qrcode"></canvas><!--生成二維碼-->
<div id="imgcode"></div><!--生成圖片-->
var QRCode = require('qrcode');
getErCode(item){//生成二維碼
    let that=this;
    that.url=item.url;
    that.$nextTick(function() {
        let canvas=document.getElementById('qrcode');
        let imgcode=document.getElementById('imgcode');
        imgcode.innerHTML='';//防止屢次生成圖片地址不變
        QRCode.toCanvas(canvas,item.url,{
            margin: 4, //二維碼內邊距,默認爲4。單位px
            height: 240, //二維碼高度
            width: 240, //二維碼寬度
        },error=>{
            var image = new Image();     //實例一個img
            image.src = canvas.toDataURL("image/png");  //轉換成base64格式路徑的png圖片
            image.style.width = "100%";    //設置樣式
            imgcode.appendChild(image);     //添加到容器中
            canvas.style.display = "none";   //隱藏掉canvas
        })
    })
}
相關文章
相關標籤/搜索