在main.js裏進行全局註冊ajax
Vue.prototype.ajax = function (){}函數
在全部組件裏可調用
this.ajax()this
// xx.js文件 var tools = {} tools.addNum = function (x, y) { return x * y } // 還能夠在這個文件裏面添加多個函數 tools.install = function (Vue, options) { Vue.prototype.$tools = tools Vue.tools = tools } export default tools
// main.js import tools from 'xx' Vue.use(tools)
// 子組件 let yy = this.$tools.addNum(6, 9) console.log(yy) // 54