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
Source:stackexchange.com