[Vuejs]-How to use axios response data in data function – vue

3πŸ‘

βœ…

You probably are looking for computed property:

data () {
  return {
    offersData: {},
  }
},
computed() {
  id() {
    return this.offersData.item && this.offersData.item[0].id;
  }
}

As for data function, it is used to define shape of state (set up the properties to be tracked) of component and give valid initial values to it. In this case, however, id should neither be a part of state (it’s always a part of offersData value, after all) nor its initial value can be calculated before offersData is set up by a remote call.

πŸ‘€raina77ow

Leave a comment