Vue mounted failed to read data in data

clipboard.png

createdthis.lasttime;

clipboard.png

mounted this.lasttimedata

clipboard.png

how can the data in created be printed in mounted

Jul.06,2021

is for asynchronous reasons.
mounted is a hook function that is called when the vue component is loaded, which should not be written in mounted.

1. If you want to use lastime, immediately after the interface returns, you should write a methods, for this specific logic and call it in the callback of the interface.
2. It's OK to write the API request function as Synchronize, but this has a cost, because you call it in created. If the request for this API is slow or there are some other problems, it will block the rendering and mounting of this component

.

is the reason for asynchrony?

methods:{
    async query(){
        const res = await this.$axios.get(url2)
        ...
        this.lasttime = this.act ...
        console.log(this.lasttime)
    }
}
created(){
   this.query()
}
mounted(){
    console.log(this.lasttime)
}

try this


Hello, you did not save the data to the Vue instance in create, and using this, in axios is not a Vue instance, so when you this.lasttime =, you create a lasttime attribute for axios and assign a value to axios, not asynchronously.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1ebc1df-28ac.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1ebc1df-28ac.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?