vue2中设置全局变量的最简单方法

在入口文件main.js中定义vue属性值:

let a = {
    b:'bbb',
    c:'ccc'
}


Vue.prototype.$http = axios;
Vue.prototype.$host = 'http://idol.fibonacci-tech.com/';
Vue.prototype.$moment = moment;
Vue.prototype.$a = a;

在任何组件中引用:

this.$host...
this.$http.post...

猜你喜欢

转载自blog.csdn.net/ruffaim/article/details/80854077