码迷,mamicode.com
首页 > Web开发 > 详细

vue导入外部js

时间:2017-08-30 21:36:50      阅读:448      评论:0      收藏:0      [点我收藏+]

标签:load   end   fun   read   文件   one   component   att   导入   

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文件的地址即可

vue导入外部js

标签:load   end   fun   read   文件   one   component   att   导入   

原文地址:http://www.cnblogs.com/zhuchenglin/p/7455203.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!