第一种操作 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文件夹下,再进行引用