当执行点击事件时,dispatch触发action中的changeCity函数,再通过commit()执行mutations中的changeCity.因为没有异步操作,没有必要执行action,可以直接执行commit()
语法糖:
computed:{
...mapState({
currentCity:'city'
})
}
相当于:
computed:{
currentCity: function(){
return this.$store.state.city
}
}