When using Nuxt async data, I am retrieving a JSON object that includes a nested array in the following structure:
"topic_list": {
"topics": [
{
"id": 9148,
"title": "A",
"views": 12
},
{
"id": 3228,
"title": "B",
"views": 88
}
]
}
The data is loaded asynchronously as shown below:
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 am looking for guidance on how to calculate the total number of views efficiently. I know I can use reduce() and assume the values need to be placed into an array, but how would this be done with asynchronously loaded data?