HLJ 发布于
2018-08-06 09:34:37

vue组件通过main.js调用外部js文件里面的方法

vue组件通过main.js调用外部js文件里面的方法

1、首先创建一个demo.js的文件,内容为
function fn() { 
  this.test=function(string){
  alert(string)
  }
}; 
module.exports = fn;
2、然后在main.js里引用并赋值
import demo from '../static/js/demo.js';
Vue.prototype.demo = demo;
3、在组件里实例化并调用dmeo里的方法
mounted: function() {
    let demo = new this.demo();
        demo.test("测试数据!")
},
当前文章内容为原创转载请注明出处:http://www.good1230.com/detail/2018-08-06/36.html
最后生成于 2023-06-18 18:28:59
此内容有帮助 ?
0