I have a user profile card that displays different measurements in boxes, such as temperature, volume and weight.
Currently I'm getting the name of each user from an axios GET request, I need to then take the ID in that data and perform another GET request with the ID which gives me a performance data, in that data I am given a performance ID which I need to use to GET a final array of measurement data.
I'm wondering how I can make the last GET request only for users that have a performance Id and then take that data of the measurements and display in each user profile{that has measurement data) for each measurement box?
It looks something like this:
- I make the first axios request in vuex and use v-for to display each user name:
GET api/profiles
which returns:
"data": [
{
"id": 1,
"name": "Joe",
},
{
"id": 2,
"name": "Max",
},
<div class="outer" v-for="(item, index) in profiles" :key="item.id" >
<p> User Name: {{ item.name }}</p>
- I then need to make another GET request for performance:
GET api/performance/{profileID}
which returns only for users who have (other users return empty data object):
mounted() {
this.$store.state.profiles.forEach((item, index) => {
axios.get('api/performance/' + this.profile[index].id)
.then(response => {
this.performanceId = response.data.data.id
})
});
}
"data": {
"id": 1,
"profile_id": 2,
.....other keys and values
}
- and lastly for the users that have a performance ID I need to get the measurements:
GET api/measurements/{profileID}/{performanceID}
which returns:
"data": {
"profileID": "2",
"perfomanceID": "1",
"data": [
{
"key": "temp",
"data": "37",
},
{
"key": "vol",
"data": "22",
},
{
"key": "weight",
"data": "200",
},
I would then like each data point to display in the box:
<div class="outer" v-for="(item, index) in profiles" :key="item.id" >
<p> User Name: {{ item.name }}</p>
<div class="box 1">Temperature: </div>
<div class="box 2">Volume: </div>
<div class="box 3">Weight: </div>
</div>
It would like this for Max's profile:
User Name: Max
Temperature: 37
Volume: 22
Weight: 200
Any help would be appreciated, thanks!