Answer the question
In order to leave comments, you need to log in
How to store user data using Vuex?
I'm making a Laravel + Vue + Vuex + API todo sheet. I want to put all the data about the user in the store. I don’t understand how to form a url (or rather, how to take the user’s id) in actions, here is the actual code:
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
let store = new Vuex.Store({
state: {
user:[],
},
mutations: {
SET_USER_TO_STATE:(state, user) => {
state.user = user;
}
},
actions: {
GET_USER({commit}) {
return axios('/api/users/{user}', { //вот url из роутов, но соответственно как сюда id авторизированного пользователя передать
method: "GET"
})
.then((user) => {
return user;
commit('SET_USER_TO_STATE', user.data);
})
.catch(error => {
console.log(error);
return error;
})
}
},
getters: {
USER(state) {
return state.user;
}
},
})
export default store;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question