Vuex

70 阅读1分钟

vuex

1.state 存数据,使用方法this.$store.state.

2.mutation 用来改变state中数据的方法,使用方法 this.$store.commit('方法名','')

3.actions 包裹mutations,使之可以异步改变state中的方法, 使用方法 this.$store.dispatch('方法名')

4.getters 从基本数据(state)派生的数据,相当于state的计算属性,使用方法 this.$store.getters.方法名

5.moudles 模块化vuex,可以让每一个模块拥有自己的state、mutation、action、getters,使得结构非常清晰,方便管理。