创建script标签的方法(定义自定义组件)
代码如下(示例):
export default {
components: {
tabVue,
'remote-js': {
render (createElement) {
return createElement('script', { attrs: { type: 'text/javascript', src: this.src } });
},
props: {
src: { type: String, required: true },
},
},
},
}
引用组件:
这里引用的是three.js这个外部js
<remote-js src="https://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-M/three.js/71/three.min.js"></remote-js>
src中使用的既是链接形式的js文件
查看效果:


dom创建完成并且插件使用正常
非常nice!!!
本文介绍了如何在Vue应用中创建一个自定义组件`remote-js`,该组件用于动态加载外部JavaScript库,例如在示例中引用了three.js。通过设置`src`属性指定JS文件的URL,成功实现DOM创建并确保插件正常工作,从而实现动态引入资源。
的js文件&spm=1001.2101.3001.5002&articleId=120918876&d=1&t=3&u=3a9450e3d36040378a3d4b65fe141037)
3490

被折叠的 条评论
为什么被折叠?



