vuex辅助函数mapActions、mapMutations传递自定义参数

mapActions传参

方式1
this.$store.dispatch('setShowLogin', true)
方式2
将 this.setShowLogin() 映射为 this.$store.dispatch('setShowLogin')
 ...mapActions([
     'setShowLogin',
 ]),
 <button @click="setShowLogin(true)">登录</button>
方式3
将 this.isLogin() 映射为 this.$store.dispatch('setShowLogin')
 ...mapActions({
     isLogin:'setShowLogin',
 }),
 <button @click="isLogin(true)">登录</button>
 或
 this.isLogin(true)

mapMutations传参

方式1
this.$store.commit('SET_SHOW_LOGIN', true)

其他传参方法基本与mapActions相同


如有问题,请联系作者,及时纠正

评论

暂无评论