vue如何让自定义函数挂到全局

在main.js里进行全局注册
Vue.prototype.ajax = function (){}

在所有组件里可调用
this.ajax

// xxx.js 组件 exports.install = function (Vue, options) { Vue.prototype.ajax = function (){ alert('aaaaaaa'); }; };
// main.js 入口
import xxxx from './commons/xxxx'
Vue.use(xxxx);
// ccc.js 子组件
this.ajax();







原文地址:https://www.cnblogs.com/gerry/p/7132453.html