在Vuex getter中访问rootState [英] Accessing rootState in Vuex getter

查看:3813
本文介绍了在Vuex getter中访问rootState的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在getter中访问 rootState

How do you access rootState in getters?

const getters = {
  getParams: rootState => {
    return rootState.route.params
  },
}

以上不起作用。这是怎么做的?

The above doesn't work. How is this done?

推荐答案

如果这个getter在一个模块中 rootState 是第三个参数。

If this getter is in a module rootState is the third arguments.

const getters = {
  getParams: (state, getters, rootState) => {
    return rootState.route.params
  }
}

这篇关于在Vuex getter中访问rootState的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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