I'm encountering issues with Axios while trying to send data to the backend. What steps should I take?
Within the
.then(response => { this.$router.push('/Log-in') return response })
section, I returned the "response" because an error message in the console indicated that 'response' is defined but never used.
This is a snippet from my vue.js file:
import axios from 'axios'
if (!this.errors.length) {
const formData = {
username: this.username,
password: this.password,
email: this.email
}
axios
.post('/api/v1/users', formData)
.then(response => {
this.$router.push('/Log-in')
return response
})
.catch(error => {
if (error.response) {
for (const property in error.response.data) {
this.errors.push(`${property}: ${error.response.data[property]}`)
}
console.log(JSON.stringify(error.response.data));
} else if (error.massege) {
this.errors.push('Something went wrong, Please try again!')
console.log(JSON.stringify(error));
}
})
}
Here's the CORS configuration in my settings.py file for Django:
CORS_ALLOWED_ORIGINS = [
'http://localhost:8000',
'http://127.0.0.1:8000/'
]