简化版 vuex ( Vue.observable )
全局变量
因为Vuex使用比较复杂, 在非大型项目中使用起来不方便, 为了简化传值操作, vue2.6之后新增此API
创建
main.js
import Vue from 'vue';
const obbStore = {
state: Vue.observable({
count: 0,
name: '李四'
}),
mutations: {
setCount(count) {
obbStore.state.count = count
},
changeName(name) {
obbStore.state.name = name
}
}
}
Vue.prototype.$obbStore = obbStore;
使用
this.$obbStore.mutations.setCount(110)
本文来自博客园,作者:极学者,转载请注明原文链接:https://www.cnblogs.com/jixuezhe/articles/15544888.html

浙公网安备 33010602011771号