I'm trying to add multiple values into an existing data object pathStats: []
Code:
data () {
return {
pathStats: []
}
}
computed: {
loadDetails() {
fse.stat('C:/').then((res) => {
let edited = res.mtime
let created = res.birthtime
this.pathStats.push([{'edited': edited}, {'created': created}])
})
}
}
I want to be able to get the values separately when I need them, e.g.:
<p>{{pathStats.edited}}</p>
<p>{{pathStats.created}}</p>
But with the current code, I get undefined when I try to console.log pathStats.created or pathStats.edited
pathStatsis an array, but you're trying to grab an object property out of it. TrypathStats[0][0].editedinstead, for example, to perform the operation on an element of the array.pathStats.edited?push({'edited': edited, 'created': created}).Object.assign(this.pathStats, {'edited': edited, 'created': created});and in yourdata(), definepathStats: {}. What this does is overwrites the values in the originalpathStatsobject with the values in another object.Object.assignmethod does the job