个人blog,欢迎关注加收藏

方法1:
// 先定义这么个组件
export default {
 components: {
  'remote-js': {
 	 render(createElement) {
   	return createElement('script', { attrs: { type: 'text/javascript', src: this.src }});
  	},
  	props: {
   		src: { type: String, required: true },
  	},
 	},
 },
}


// 在需要的地方这样调用
<remote-js src="https://g.alicdn.com/dingding/dinglogin/0.0.2/ddLogin.js">
</remote-js>



方法2:
cdn方式引入的话
首先有一点要求, script 必须在 index.html 中的 <div id="app"></div> 上面
在 main.js 中 通过 window 获取对象
const Foo = window.foo
Vue.prototype.Foo = Foo
vue 文件里:
this.Foo(params) 




Logo

前往低代码交流专区

更多推荐