On the problem of updating rendering of vue data Array

The

page loads, then gets the data from the background, and then binds it to the array in data with set. If you want to use the updated data in mounted, you can"t get it all the time, and it should be a problem of asynchronous loading, but you can"t solve it.

  //axios   created
    innerBase().then(res =>{
      this.$set(this.$data,"musicList",res.data.playlist.tracks)  
      //musicList
    })
data {
    return {
        musicList:""
    }
}
//mounted
     console.log(this.musicList)  // null
     this.playMusic(this.musicList[0]);
Mar.02,2021

because it is an asynchronous call, by the time your data arrives, the execution in mounted will be finished, so you can not get the data
you can put the methods in created into mounted to execute. After returning the data, you can perform other operations


the life cycle of vue is not fully understood. When the asynchronous operation has a response, mounted is finished. If you want to call it when data has data, You can use updated or beforeUpdate lifecycle hooks

Menu