My VueJS app showcases activity data fetched from Strava, organized by week throughout a span of 20 weeks. I am facing a challenge where the API object is visible but inaccessible for each property.
Here are some key snippets from the Single File Component (SFC).
DATA
weekly_total_data
will continue to expand as the weeks progress
data() {
{
return {
activity_weeks: [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20],
weekly_total_data:
[{"week_number":3,"total_distance":39877.6,"total_moving_time":11841},
{"week_number":2,"total_distance":58596.4,"total_moving_time":18719},
{"week_number":1,"total_distance":41347.5,"total_moving_time":12796}]
}
}
}
FUNCTION
Accessing the data
matchWeeklyTotals(){
var x = this.weekly_total_data
console.log(x)
return x
}
},
TEMPLATE
Iterating through the weeks, obtaining an index for each week, and utilizing it to showcase the relevant data per week
<div v-for="(week, week_index) in this.activity_weeks" v-bind:value="week._id">
<div class="container max-w-xl mx-auto">
<h2 class="text-2xl">Week {{week}}: {{ (matchWeeklyTotals()[week_index])}}</h2>
</div>
</div>
Currently, I can exhibit the object, but when attempting
matchWeeklyTotals()[week_index][total_distance]
, it results in failure.
Various attempts with JSON.parse have also been made.
Any assistance on accessing the total_distance
and total_moving_time
would be greatly appreciated.