1.npm install html2canvas --save
2.import html2canvas from 'html2canvas' 在使用的页面进入引入
3.方法
download(){
html2canvas(document.getElementById('main'),{
backgroundColor:'white',
useCORS:true,
scale:0.6
}).then((canvas)=>{
canvas.toBlob((blobData)=>{
let formData=new FormData()
this.$getInterfaceData(ApiSetting.upLoadPics,'POST',formData,'uploadFile',{'Content-Type':'application/x-www-form-urlencoded'}).then(res=>{
this.fileId=res.data.data.fileId
})
})
})
}
4.页面 ,截图哪里的内容,就用div id='main' 进行包裹
5.调用,点击事件的调用 例如
<button @click="download">获取Id</button>