vuex 中子模块怎么调用root级(或者其他模块的的mutations、actions?

查看:879
本文介绍了vuex 中子模块怎么调用root级(或者其他模块的的mutations、actions?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

vuex 中子模块的actions或者mutations 怎么调用 root级(或者其他模块的)的mutations、actions?

知道 vuex 中子模块的actions或者mutations 怎样获取 root 级的states 和 getters。

解决方案

//vuex/module.js

test(context,data){
    setTimeout(()=>{
        context.commit('updateActiveName',data);
        //调用父级的 actions 或者 mutations
        context.commit('setLocation',{key_root:data},{root:true});
        context.dispatch('updateLocation',{key_root:data},{root:true});
    },10);
}

page.vue

created(){
    //vuex mutation
    this.$store.commit('setLocation',{key1:"mutation"});
    //vuex module mutation
    this.$store.commit('filter/updateActiveName',"filter/mutation");
    //vuex action
    this.$store.dispatch('updateLocation',{key2:"action"});
    //vuex module actions
    this.$store.dispatch('filter/test',"filter/actions");
}

这篇关于vuex 中子模块怎么调用root级(或者其他模块的的mutations、actions?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆