When working with VueJs, I came across a situation where I defined an object inside a method. My goal was to then use that object in conjunction with axios like the example below:
data() {
return {
name : '',
password: '',
email: ''
}
},
methods: {
submit() {
const sendData = {
name: this.name,
password: this.password,
email: this.email
}
axios.post('http://localhost:8000/api/users', sendData)
.then(response => {
console.log(response);
})
.catch(error => {
console.log(error)
})
}
}
Upon execution, I encountered the following error message:
ReferenceError: sendData is not defined