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)
}
};
Source:stackexchange.com