Using Nuxt async data, I am fetching a JSON object with a nested array in the following format:
"topic_list": {
"topics": [
{
"id": 9148,
"title": "A",
"views": 12
},
{
"id": 3228,
"title": "B",
"views": 88
}
]
}
The data is being loaded asynchronously:
export default {
data () {
return { topics: 'default', users: '0', views: '0', total: [] }
},
asyncData ({ params }, callback) {
axios.get(`data.json`)
.then((res) => {
callback(null, { topics: res.data.topic_list.topics, users: res.data.users,
})
})
}
}
I would like to know what would be the best approach to calculating the sum total of all views. I am aware of reduce() and imagine these values need to be pushed into an array - but how to do this with data loaded asynchronously?
topicsupdatesres.data.views?