I'm working on a small project using VueJS and I would like to know if my code is considered as a good practice:
created(){
this.fetch()
}
methods: {
fetch(){
// axios request
}
}
You are calling a Vue method from the created life cycle hook. That's perfectly fine
if you plan to add more stuff into your created block which could depending your fetched data then you should keep in mind you have to await
your data
async created(){
await this.fetch()
// other stuff here which needs the data above
}
methods: {
fetch(){
// axios request
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.