npm install html2canvas --savehtml
import html2canvas from 'html2canvas'
html2canvas(el,options).then(canvas=>{})npm
html2canvas(document.getElementById('box'),{ backgroundColor:null, useCORS:true }).then((canvas)=>{ this.dataURL = canvas.toDataURL("image/jpeg",1) console.log(this.dataURL) })
截取出某個div內部的樣式(box),將他們繪畫成爲canvascanvas
1.圖片不清晰:跨域
須要將背景圖片換爲img圖片微信
2.請求的數據圖片加載不上this
須要設置跨域spa
useCORS:true插件
3.文字不清晰:code
查看百度便可htm
html2canvas(document.getElementById('box'),{ backgroundColor:null, useCORS:true }).then((canvas)=>{ this.dataURL = canvas.toDataURL("image/jpeg",1) console.log(this.dataURL) Wechat.share({ message:{ title:'text', description:'this is description', thumb: "",//分享時候能夠看到的圖 media:{ type:Wechat.Type.IMAGE, image:this.dataURL, } }, scene:Wechat.Scene.SESSION//分享到好友
},()=>{ alert('success') },()=>{ alert('error') }) })