[Vuejs]-Laravel Vue: Axios 401 error on form submit

3👍

Your axios function is not well formatted. It should be like this:

axios.post('/api/saveUser', {
    id: this.id,
    name: this.name,
    email: this.email,
    password: this.password
}, {
  headers: {
    Authorization: 'Bearer ' + localStorage.getItem('token')
  },
}).then(response => {
    console.log(response.data);
    this.$emit('userSaved')
}).catch(error => {
    console.log(error)
});

Leave a comment