vue 引入外部js文件 - 配置component
1.main.js 2.importJs.js// 导入外部jsimport Vue from 'vue'// 导入外部jsimport Vue from 'vue'Vue.component('remote-script', {render: function (createElement) {var self = this;...
·
1.main.js
2.importJs.js
// 导入外部js
import Vue from 'vue'
// 导入外部js
import Vue from 'vue'
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
}
}
});
3.vue使用
<remote-script src="https://pv.sohu.com/cityjson?ie=utf-8"></remote-script>
4.输出
更多推荐
已为社区贡献9条内容
所有评论(0)