安裝 npm install --save html2canvas
使用 home.vue
<div ref="downloadRef">測試內(nèi)容</div>
import html2canvas from 'html2canvas'
download() {
const downloadRef = this.$refs.downloadRef
html2canvas(downloadRef, {
background: '#ffffff',
useCORS: true,
scale: 1,
dpi: 350,
width: downloadRef.offsetWidth,
height: downloadRef.offsetHeight
}).then((canvas) => {
var a = document.createElement('a') //添加一個下載標簽
a.download = 'pic'
// 設置圖片地址
a.href = canvas.toDataURL('image/png')
a.click()
})
}
??!報錯 Uncaught (in promise) Unable to find element in cloned iframe

原因:使用了 elementUI中的<el-popover>組件,掛載到body里的文章來源:http://www.zghlxwxcb.cn/news/detail-802915.html
解決:文章來源地址http://www.zghlxwxcb.cn/news/detail-802915.html
<el-popover
:placement="placement"
trigger="click"
width="200"
popper-class="qrcode-popover"
@after-leave="hidePopover"
:append-to-body="false" //不添加到body里就行了
>
到了這里,關于vue中使用html2canvas報錯 Unable to find element in cloned iframe的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!