[Vuejs]-How to access store state from a different store module in vuex?

2👍

Actions take a context object as parameter, you can use it to access rootState. Check documentation for other available options.
https://vuex.vuejs.org/api/#actions

const actions = {
  async fetchData({commit, rootState}) {
    const headers = {
        authorization: "Bearer " + rootState.auth.user.token,
    };
    let resp = await axios.get("product", {
      headers
    });
    await commit("SET_PRODUCTS", resp.data)
  }

};
👤linusw

Leave a comment