lesson 211: store mutations
This commit is contained in:
parent
0a1432c828
commit
8be97b49de
|
@ -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');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
<template>
|
||||
<button @click="addOne">Add 1</button>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
methods: {
|
||||
addOne() {
|
||||
this.$store.commit('increment');
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
|
@ -5,6 +5,11 @@ const store = createStore({
|
|||
return {
|
||||
counter: 0
|
||||
};
|
||||
},
|
||||
mutations: {
|
||||
increment(state) {
|
||||
state.counter = state.counter + 1;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Reference in New Issue