Answer the question
In order to leave comments, you need to log in
How to update state after PATCH request?
I need to update profile in state after PATCH request.
How to do it?
const state = {
status: null,
profile: {},
token: null || ''
const actions = {
// для удобства я убрл другие actions
SET_PROFILE: ({commit}, id, data) => {
axios.patch('/profile/user/' + id + '/', data)
.then(response => {
console.log('it is OK')
})
.catch(error => {
console.log(error, 'something went wrong')
})
},
// тут тоже убрал для простоты mutations.
const mutations = {
GET_PROFILE: (state, profile) => {
state.profile = profile
},
}
const getters = {
isAuthenticated: state => !!state.token,
authStatus: state => state.status,
profile: state => state.profile,
token: state => state.token
}
}
Answer the question
In order to leave comments, you need to log in
const state = {
status: null,
profile: {},
token: null,
const actions = {
fetchProfile: ({commit}, id, data) => {
axios.patch('/profile/user/' + id + '/', data)
.then(response => {
commit('PROFILE_SET', response.profile);
})
.catch(error => {
console.log(error, 'something went wrong')
})
},
const mutations = {
PROFILE_SET: (state, profile) => {
state.profile = profile
},
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question