I'm using axios to post two requests to update a user profile in my app:
methods: {
updateProfileInfo () {
let token = this.getAuthToken
return axios.patch(`/api/profiles/${this.userid}/`, {
bio: this.bio,
dob: this.dob,
media_url: this.media_url
}, {
headers: {
'Authorization': 'Token ' + token
}
})
},
updateUserInfo () {
let token = this.getAuthToken
return axios.patch(`/rest-auth/user/`, {
username: this.username,
first_name: this.firstname,
last_name: this.lastname
}, {
headers: {
'Authorization': 'Token ' + token
}
})
},
updateProfile () {
axios.all([this.updateProfileInfo(), this.updateUserInfo()])
.then(axios.spread(function (resProfile, resUser) {
this.$store.commit('SET_USERNAME', this.username)
console.log('spread...')
console.log(resProfile)
console.log(resUser)
})).catch(err => {
console.log(err)
})
}
This is generating the following error (trying to commit username inside updateProfile
):
TypeError: Cannot read property '$store' of null
at eval (Profile.vue?bbca:206)
at wrap (spread.js?3c41:25)
at <anonymous>
Here are my mutations
in the Vuex store:
mutations: {
SET_TOKEN_AUTH(state, key) {
state.token = key
},
SET_USERID(state, id) {
state.userid = id
},
SET_USERNAME(state, username) {
state.username = username
},
USER_LOGOUT(state) {
state.token = null
state.userid = null
state.username = null
}
},