2020-08-19
关键:new 一个实例 + mixin computed
store.js
// 全局状态存储
export const state = new Vue({
data: () => ({
userType: -1
}),
});
index.js
import {state} from './store';
// 组件通信方案二:全局公用状态存储 store.js
Vue.mixin({
computed: {
state: () => ({
...state,
}),
},
});
app.vue
import {state} from './store';
// state 赋值
state.data = res.data;
A-Component
// 取值
this.state.data
网友评论