主要用到兩個庫:javascript
html2canvashtml
1.先生成二維碼覆蓋在廣告圖上面java
2.html轉canvas canvas轉成base64圖片canvas
3.廣告圖src替換爲base64微信
注意:微信內不支持保存canvas爲圖片,因此多了第三步app
async generateQrcode() { this.showQr = true; let canvas1 = qrcanvas({ data: decodeURIComponent( "http://xiaoshuiw.com/jxjy_app/user/register?code=188" ), size: 80 }); setTimeout(() => { this.$refs.ttt.appendChild(canvas1); html2canvas(this.$refs.qrmain,{backgroundColor: null}).then(canvas => { this.$refs.ttt.innerHTML="" this.$refs.img.src=canvas.toDataURL("image/png") }); }, 100); }