html页面需要生成长截图或者PDF,用html2canvas, 页面复杂耗时太长
import html2canvas from 'html2canvas'
// import jsPDF from 'jspdf'
shotPic() {
const targetDom = document.querySelector('.target-div')
// 此处是实现滚动元素长截图的关键 start
const copyDom = targetDom.cloneNode(true)
copyDom.setAttribute('id', 'copyDom')
// 更改id 避免与targetDom id重复
copyDom.style.width = targetDom.scrollWidth + 'px'
copyDom.style.height = targetDom.scrollHeight + 'px'
document.querySelector('.parent-div').appendChild(copyDom)
// 此处是实现滚动元素长截图的关键 end /* *如不需要长截图,或者要截取的元素无滚动即完全显示。 *下方要截取的元素改为targetDom,并把copyDom相关代码删除即可 */
html2canvas(copyDom, {