因为公司的开发需要,安装了html2canvas插件。
但是坑爹的是,在网页、android上测试正常,在ios上却使用不了。
原因是html2canvas1.0.0-rc.4以上版本不兼容ios。
特此记录下解决的方法:
1.vue环境下运行以下指令:
npm uninstall html2canvas
npm i html2canvas@1.0.0-rc.4;
2.修改程序:
let that = this
let ref = this.$refs.result // 截图区域
console.log('开始截图')
new html2canvas(ref, { //关键在于new
useCORS: true,
removeContainer: true,
allowTaint: false,
width: window.screen.availWidth,
// height: window.screen.availHeight,
windowWidth: document.body.scrollWidth,
// windowHeigt: document.body.scrollHeight,
x: 0,
y: 0,
}).then(canvas => {
console.log('截图中')
let dataURL = canvas.toDataURL('image/png')
that.dataURL = dataURL.replace(/[\r\n]/g, '')
console.log('dataURL=' + dataURL)
Toast.clear()
this.showModel = true
})