lesson 211: store mutations

This commit is contained in:
Andreas Zweili 2021-05-04 21:49:40 +02:00
parent 0a1432c828
commit 8be97b49de
3 changed files with 23 additions and 2 deletions

View File

@ -1,6 +1,7 @@
<template>
<base-container title="Vuex">
<the-counter></the-counter>
<change-counter></change-counter>
<button @click="increaseCounter">Add 1</button>
</base-container>
</template>
@ -8,16 +9,18 @@
<script>
import BaseContainer from './components/BaseContainer.vue';
import TheCounter from './components/TheCounter.vue';
import ChangeCounter from './components/Changecounter';
export default {
components: {
BaseContainer,
TheCounter
TheCounter,
ChangeCounter
},
methods: {
increaseCounter() {
this.$store.state.counter++;
this.$store.commit('increment');
}
}
};

View File

@ -0,0 +1,13 @@
<template>
<button @click="addOne">Add 1</button>
</template>
<script>
export default {
methods: {
addOne() {
this.$store.commit('increment');
}
}
};
</script>

View File

@ -5,6 +5,11 @@ const store = createStore({
return {
counter: 0
};
},
mutations: {
increment(state) {
state.counter = state.counter + 1;
}
}
});