import html2canvas from 'html2canvas'
//保存图片
saveImg() {
html2canvas(this.$refs.table, {
useCORS: true,
backgroundColor: null
}).then(canvas => {
const dataUrl = canvas.toDataURL('images/jpg')
var aa = this.base64ToFile(dataUrl,'test');
})
},
// base64转file文件
base64ToFile(base64, fileName) {
var byteString = atob(base64.split(',')[1])
var mimeString = base64.split(',')[0].split(':')[1].split(';')[0]
var ab = new ArrayBuffer(byteString.length)
var n = byteString.length;
let u8arr = new Uint8Array(ab);
while (n--) {
u8arr[n] = byteString.charCodeAt(n);
}
return new File([u8arr], fileName, { type: mimeString });
},
// base64转buffer
dataURItoBlob (dataURI) {
var byteString = atob(dataURI.split(',')[1])
var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0]
var ab = new ArrayBuffer(byteString.length)
var ia = new Uint8Array(ab)
for (var i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i)
}
return new Blob([ab], { type: mimeString })
},
网友评论