学习vuex!

This commit is contained in:
2022-11-29 15:29:41 +08:00
parent bd3a9dc825
commit 78b1aa52f2
4 changed files with 29 additions and 11 deletions

View File

@@ -2,7 +2,7 @@
* @Author: Kane
* @Date: 2022-11-29 11:36:29
* @LastEditors: Kane
* @LastEditTime: 2022-11-29 14:04:19
* @LastEditTime: 2022-11-29 15:26:38
* @FilePath: \hello-cli\src\components\vuex\App1.vue
* @Description:
*
@@ -10,7 +10,7 @@
-->
<template>
<div class="container">
<h1>计数器一{{ count }}</h1>
<h1>计数器一{{ this.$store.state.count }}</h1>
<el-button type="primary" v-on:click="addCount()">更新计数器</el-button>
</div>
</template>
@@ -25,7 +25,7 @@ export default {
},
methods: {
addCount() {
this.count++;
this.$store.commit("increment");
},
},
};

View File

@@ -2,7 +2,7 @@
* @Author: Kane
* @Date: 2022-11-29 13:10:21
* @LastEditors: Kane
* @LastEditTime: 2022-11-29 14:04:50
* @LastEditTime: 2022-11-29 15:29:07
* @FilePath: \hello-cli\src\components\vuex\App2.vue
* @Description:
*
@@ -10,8 +10,8 @@
-->
<template>
<div class="container">
<h1>计数器二{{ count }}</h1>
<el-button type="primary" v-on:click="addCount()">更新计数器</el-button>
<h1>计数器二{{ this.$store.state.count }}</h1>
<el-button type="danger" v-on:click="addCount()">更新计数器</el-button>
</div>
</template>
@@ -25,7 +25,7 @@ export default {
},
methods: {
addCount() {
this.count++;
this.$store.commit("increment");
},
},
};