From 2f52f23e1ad1b428208004a7dde3b5649d2b18dd Mon Sep 17 00:00:00 2001 From: sw_pc Date: Tue, 12 Sep 2023 19:24:03 +0800 Subject: [PATCH] =?UTF-8?q?Count=E7=BB=84=E4=BB=B6=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- course/vue2/vuex/heima/src/App.vue | 11 ++++- .../vue2/vuex/heima/src/components/Count.vue | 45 +++++++++++++++++++ course/vue2/vuex/heima/src/store/index.js | 25 +++++++++++ 3 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 course/vue2/vuex/heima/src/components/Count.vue diff --git a/course/vue2/vuex/heima/src/App.vue b/course/vue2/vuex/heima/src/App.vue index 55df315..53492b4 100644 --- a/course/vue2/vuex/heima/src/App.vue +++ b/course/vue2/vuex/heima/src/App.vue @@ -1,17 +1,20 @@ @@ -25,4 +28,8 @@ export default { color: #2c3e50; margin-top: 60px; } + +#hello { + display: none; +} diff --git a/course/vue2/vuex/heima/src/components/Count.vue b/course/vue2/vuex/heima/src/components/Count.vue new file mode 100644 index 0000000..37cfbcb --- /dev/null +++ b/course/vue2/vuex/heima/src/components/Count.vue @@ -0,0 +1,45 @@ + + + + + diff --git a/course/vue2/vuex/heima/src/store/index.js b/course/vue2/vuex/heima/src/store/index.js index ceffa8e..0efce32 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: { } -- GitLab