How to access the getter from another vuex module?

前端 未结 2 1138
别跟我提以往
别跟我提以往 2021-01-30 19:45

Within a vuex getter I know it is possible to access the state from another vuex module like so:

pages: (state, getters, rootState) => {
    console.log(rootS         


        
2条回答
  •  迷失自我
    2021-01-30 20:30

    Had to dig through the documentation but I found it:

    https://vuex.vuejs.org/en/api.html

    (Ctrl+F search for RootGetters on that page)

    My code becomes:

    pages: (state, getters, rootState, rootGetters) => {}
    

    Beware that all rootGetters are global and you no longer use it like rootState where you would prefix the state by the module name.

    You simply call a getter from another module like so:

    rootGetters.activeFilters
    

    Hopefully this will help someone out in the future who is running into this as well.

提交回复
热议问题