基礎用法
html2canvas(this.$refs.heihie, {
backgroundColor: '#9A91F8', //背景色
useCORS: true //允許圖片跨域
}).then(canvas => {
//生成base64圖片
this.imgData = canvas.toDataURL("image/jpeg");
})
注意:
1 . 需下載以下版本 "html2canvas": "1.0.0-rc.4", 否則ios低版本系統會有bug,版本過高的降下來吧 別給自己留bug
2. 如果需要繪制圖像,需要監聽這張圖片加載完成之后在進行截取,否則ios部分機型無法截取到圖像。
解決辦法:利用img標簽的complete屬性 true為圖片加載完畢
