0
Galera. I have a problem right now. I was able to solve the 400 error, but now I’m not able to return the student’s data by the student’s id. Follow my code below:
data() {
return {
student: {
name: "",
lastname: "",
telephone: ""
}
}
},
methods: {
async updateStudent() {
const url = http://localhost:5000/students/student
await axios.put(url, {
name: this.student.name,
lastname: this.student.lastname,
telephone: this.student.telephone
})
.then((response) => {
console.log(response)
this.student = response.data
})
.catch((error) => {
console.log("Erro!! " + error)
})
},
clean() {
this.student.name = ""
this.student.lastname = ""
this.student.telephone = ""
},
created() {
this.updateStudent()
this.clean()
}
}
}
mistakes:
[Vue warn]: Error in v-on handler: "TypeError: Cannot read property 'student' of null"
found in
---> <FormSearchStudent>
<SearchStudent> at src/pages/Students/SearchStudent.vue
<App> at src/App.vue
<Root>
warn @ vue.runtime.esm.js?2b0e:619
logError @ vue.runtime.esm.js?2b0e:1884
globalHandleError @ vue.runtime.esm.js?2b0e:1879
handleError @ vue.runtime.esm.js?2b0e:1839
invokeWithErrorHandling @ vue.runtime.esm.js?2b0e:1862
invoker @ vue.runtime.esm.js?2b0e:2179
original._wrapper @ vue.runtime.esm.js?2b0e:6917
TypeError: Cannot read property 'student' of null
at submit (eval at ./node_modules/cache-loader/dist/cjs.js?{"cacheDirectory":"node_modules/.cache/vue-loader","cacheIdentifier":"574491ba-vue-loader-template"}!./node_modules/vue-loader/lib/loaders/templateLoader.js?!./node_modules/cache-loader/dist/cjs.js?!./node_modules/vue-loader/lib/index.js?!./src/components/Students/FormSearchStudent.vue?vue&type=template&id=6e70ea68& (app.js:1502), <anonymous>:15:43)
at invokeWithErrorHandling (vue.runtime.esm.js?2b0e:1854)
at HTMLFormElement.invoker (vue.runtime.esm.js?2b0e:2179)
at HTMLFormElement.original._wrapper (vue.runtime.esm.js?2b0e:6917)
logError @ vue.runtime.esm.js?2b0e:1888
globalHandleError @ vue.runtime.esm.js?2b0e:1879
handleError @ vue.runtime.esm.js?2b0e:1839
invokeWithErrorHandling @ vue.runtime.esm.js?2b0e:1862
invoker @ vue.runtime.esm.js?2b0e:2179
original._wrapper @ vue.runtime.esm.js?2b0e:6917
Usually when using the put method, one should pass a
id
url. Example: http://localhost:5000/Students/student/1 <-- put an id here. Probably your code is falling in the catch of the await function. That’s why the mistake.– Danizavtz
I tried to do by if was just doing post request. I’ll have to make an adjustment to the api and front-end to resolve this and then comment again if it went right or wrong.
– Wellington César
danizavtz the post I tidied up. I made the adjustment recommended by you and it worked.
– Wellington César
Congratulations on the implementation.
– Danizavtz
denizavtz. As for the user search for id I gave up trying to implement. I will implement delete q is the same logic as put, I have to pass id on route
– Wellington César