第一種操作 Dom引入js:
export default { mounted() { const s = document.createElement('script'); s.type = 'text/JavaScript'; s.src = '你的需要的js文件地址'; document.body.appendChild(s); }, }
第二種使用 createElement 方法:
export default { components: { 'remote-js': { render(createElement) { return createElement( 'script', { attrs: { type: 'text/JavaScript', src: '你的需要的js文件地址', }, }, ); }, }, }, } // 使用 <remote-js></remote-js> 在頁面中調用
當我在使用第一種方式進行js文件引入時,出現net::ERR_ABORTED報錯信息,經過檢查發現,引入的js文件存放的位置不正確,應該將js文件放到static文件夾下,再進行引用
