- 方法一:http://www.jianshu.com/p/04dffe7a6b74
//在mian.js中寫入函數
Vue.prototype.changeData = function (){ alert('執行成功'); }
//在所有組件里可調用函數
this.changeData();
- 方法二:
// 寫好自己需要的base.js文件
exports.install = function (Vue, options) { Vue.prototype.changeData = function (){ alert('執行成功'); }; };
// main.js 引入並使用
import base from './base' Vue.use(base);
//在所有組件里可調用函數
this.changeData();
目錄結構: