the official website is too simple.
/ / store.js
export default {
state : {
count : 20
},
addsome (num) {
this.state.count = this.state.count+Number(num)
}
}
/ / component.js
<template>
<div id="header">
<button @click="add"></button>
{{initState2}}
</div>
</template>
<script>
import store from "../../vuex/storeModule"
name : "home",
data () {
return {
initState: store.state.count
}
}
methods : {
add () {
store.addsome(202)
}
}
</script>
button