vue文件中引入外部js

时间:2021-11-22 06:42:03

1.在项目的入口文件中(app.js)定义remoteScript标签

Vue.component('remote-script', {

    render: function (createElement) {
var self = this;
return createElement('script', {
attrs: {
type: 'text/javascript',
src: this.src
},
on: {
load: function (event) {
self.$emit('load', event);
},
error: function (event) {
self.$emit('error', event);
},
readystatechange: function (event) {
if (this.readyState == 'complete') {
self.$emit('load', event);
}
}
}
});
}, props: {
src: {
type: String,
required: true
}
}
}); 2.在所需要的引入外部js的页面使用
<remote-script src=""></remote-script>
src位置的地址里面填要引入js文件的地址即可