Uncaught (in promise) Error:Element is not attached to a Document
解决方法:
我在vue中使用html2canvas报的错,找不到元素。
错误写法:
1.标签
<div id="range" ></div>
2.将页面标签中内容生成图片代码
this.$nextTick(function () {
var self = this;
$("#downloadBill").click(function () {//self.$refs.range
html2canvas($("#range")).then(function (canvas) {
var imgUri = canvas.toDataURL("image/png").replace("image/png", "image/octet-stream"); // 获取生成的图片的url
window.location.href = imgUri; // 下载图片
});
});
})
正确写法:
1.标签
<div id="range" ref="range"></div>
2.将页面标签中内容生成图片代码
this.$nextTick(function () {
var self = this;
$("#downloadBill").click(function () {//self.$refs.range
html2canvas(self.$refs.range).then(function (canvas) {
var imgUri = canvas.toDataURL("image/png").replace("image/png", "image/octet-stream"); // 获取生成的图片的url
window.location.href = imgUri; // 下载图片
});
});
})