单独零散的函数
在main.js里进行全局注册
Vue.prototype.ajax = function (){}
在所有组件里可调用
this.ajax()多个函数定义在一个对象里
// 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.jsimport tools from 'xx'Vue.use(tools)
// 子组件let yy = this.$tools.addNum(6, 9)console.log(yy) // 54
来源: