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

时间:2025-04-07 22:17:00

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

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


Vue.prototype.$http = axios;
Vue.prototype.$host = '/';
Vue.prototype.$moment = moment;
Vue.prototype.$a = a;

在任何组件中引用:

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

相关文章