+
+
当前求和为:{{ $store.getters.bigSum }}
+
+
+
+
+
+
+
+
+
+
+
diff --git a/course/vue2/vuex/heima/src/store/index.js b/course/vue2/vuex/heima/src/store/index.js
index ceffa8e3acbd629064905827e0192b19c42ad254..0efce327b5e2ad7b1a19a40e996eb253084a4c4e 100644
--- a/course/vue2/vuex/heima/src/store/index.js
+++ b/course/vue2/vuex/heima/src/store/index.js
@@ -5,12 +5,37 @@ Vue.use(Vuex)
export default new Vuex.Store({
state: {
+ sum:0 //当前的和
},
getters: {
+ bigSum(state) {
+ console.log(state)
+ return state.sum * 10
+ }
},
mutations: {
+ ADD(state,value){
+ console.log("mutations ADD")
+ state.sum += value
+ },
+ SUBTRACT(state,value){
+ console.log("mutations SUBTRACT")
+ state.sum -= value
+ }
},
actions: {
+ addOdd(context,value){
+ console.log("actions中的addOdd被调用了")
+ if(context.state.sum % 2){
+ context.commit('ADD',value)
+ }
+ },
+ addWait(context,value){
+ console.log("actions中的addWait被调用了")
+ setTimeout(()=>{
+ context.commit('ADD',value)
+ },500)
+ },
},
modules: {
}