Vuex is an easy to use and performant solution to handle state management. It makes it a breeze to manage large-scale Vue.js applications and ensures a predictable way to mutate the state by exposing a store.
Vuex是一种易于使用且性能卓越的解决方案,用于处理状态管理。 它使管理大型Vue.js应用程序变得轻而易举,并通过暴露商店来确保以可预测的方式改变状态的方式。
You may already know about Vuex, but if you don’t Joshua Bemenderfer gave us a great introduction.
您可能已经了解Vuex,但是如果您不了解Vuex,Joshua Bemenderfer会给我们提供很好的介绍 。
You can define modules in your Vuex store as follows:
您可以在Vuex存储中定义模块,如下所示:
const dogs = {
state: {
data: []
},
mutations: {
addDog(state, dog) {
state.data.push(dog)
}
}
}
const store = new Vuex.Store({
modules: {
dogs
}
});
Usually a large application has several modules. All of them are defined statically in their own file, and combined together when calling new Vuex.Store
. That’s what you should do in practically all cases.
通常,大型应用程序具有多个模块。 所有它们都在自己的文件