亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

將 Canvas 應用到我的 Vue.js 項目時出錯

將 Canvas 應用到我的 Vue.js 項目時出錯

阿波羅的戰車 2023-07-20 17:39:01
我想獲取我的 vue.js 項目的屏幕截圖。因此我將它用于 html2canvas。我使用以下步驟來應用 html2canvas。第 1 步-:將“html2canvas”安裝到我的項目中npm install html2canvas步驟2-:在我的項目代碼中導入html2 canvas。項目代碼-:<template>  <div class="hello">    <div id="photo">      <p>This is vue screenshor</p>    </div>    <button v-on:click="screenshot">Take Picture</button>  </div></template><script>//import html2canvas from 'vue-html2canvas';import html2canvas from 'html2canvas';export default {  name: 'HelloWorld',  data () {    return {      msg: 'Welcome to Your Vue.js App'    }  },  methods:{    screenshot(){      console.log('Function Screenshot');    html2canvas(document.getElementById('photo')).then(canvas => {      document.body.appendChild(canvas)    });    }  }}</script>但我正在運行這個項目,它給出以下錯誤 -:ReferenceError: html2canvas is not defined我如何解決這個問題?
查看完整描述

1 回答

?
慕標琳琳

TA貢獻1830條經驗 獲得超9個贊

我解決了這個錯誤。從“html2canvas”中刪除導入語句并按如下方式更改我的功能


 screenshot(){

      const html2canvas = require('html2canvas');

      console.log('Function Screenshot');

      html2canvas(document.getElementById('photo')).then(function(canvas){

        document.body.appendChild(canvas)

     });

 }


查看完整回答
反對 回復 2023-07-20
  • 1 回答
  • 0 關注
  • 137 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號