state.js
export default new Vuex.Store({
state: {
count: 0,
text: 'current count:'
},
mutations: {
add1 (state) {
state.count++
},
add2 (state, payload) {
state.count += payload
}
}
})
直接通过this.$store.xxxxxxxx调用
<template>
<div id="app">
<div class="currentCount">{
{
this.$store.state.text}}{
{
this.$store.state.count}}</div>
<button @click="handleBtnAdd1">+1</button>
</div