<div id="app"> <p>{{count}}</p> <p> <button @click="addclick">+</button> <button @click="reduceclick">-</button> </p> </div>
let store = new Vuex.Store({ state:{ count:0 }, mutations:{ add:state => state.count++, reduce:state => state.count-- }, actions:{ // add(){ // store.commit('add') // }, // reduce(){ // store.commit('reduce') // } add(){ return new Promise(resolve=>{ setTimeout(function(){ store.commit('add'); resolve() },1000) }) }, reduce(){ return new Promise(resolve=>{ setTimeout(function(){ store.commit('reduce') },1000) }) } } }) let vm = new Vue({ el:'#app', data:{}, computed:{ count(){ return store.state.count } }, methods:{ addclick(){ store.dispatch('add') }, reduceclick(){ store.dispatch('reduce') } } })