如何使用Vuex模块? const store = new Vuex.Store({ modules: { counter: { state: { count: 0 },
const store = new Vuex.Store({
modules: {
counter: {
state: {
count: 0
},
mutations: {
increment (state) {
state.count++
},
decrement (state) {
state.count--
}
}
}
}
})
this.$store.state.counter.count
this.$store.commit("counter/increment")
const store = new Vuex.Store({
modules: {
counter: {
namespaced: true,
state: {
count: 0
},
mutations: {
increment (state) {
state.count++
},
decrement (state) {
state.count--
}
}
}
}
})
store.reGISterModule("counter", {
state: {
count: 0
},
mutations: {
increment (state) {
state.count++
},
decrement (state) {
state.count--
}
}
})
this.$store.dispatch("counter/increment")
this.$store.getters["counter/count"]
const store = new Vuex.Store({
plugins: [
// ...
]
})
store.subscribe((mutation, state) => {
// ...
})
store.dispatch("counter/incrementAsync")
const store = new Vuex.Store({
plugins: [
// ...
VuexPersist.plugin
]
})
--结束END--
本文标题: Vuex模块化常见问题解答:一网打尽,让你无忧开发
本文链接: https://lsjlt.com/news/561959.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0