ARTICLE DETAIL

资讯详情

深耕网站建设、视觉设计与SEO优化的一线实战洞察。

Vue中vuex状态管理actions用法

Vue中vuex状态管理actions用法

<div>{{num}}</div>

<button @click="add">++</button>

 

<script>
import SaleCard from "../../components/SaleCard.vue";
import { mapState,mapActions } from 'vuex'
export default {
name: 'HomeIndex',
components:{
SaleCard
},
computed:{
...mapState(['num']),
},
methods:{
add(){
this.$store.dispatch('addAsync',5)
}
...mapActions(["addAsync"])
}
}
</script>

 

  actions:{

    addAsync({commit},n){
       commit('madd',n)
    }

  }
返回列表