码上敲享录 > vue.js常见问题详解 > Uncaught (in promise) Error:Element is not attached to a Document

Uncaught (in promise) Error:Element is not attached to a Document

上一章章节目录下一章 2020-08-14已有2571人阅读 评论(0)

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; // 下载图片

                 });

             });

         })


向大家推荐《Activiti工作流实战教程》:https://xiaozhuanlan.com/activiti
0

有建议,请留言!

  • *您的姓名:

  • *所在城市:

  • *您的联系电话:

    *您的QQ:

  • 咨询问题:

  • 提 交