I am trying to make my code Dynamic without using any hard code. And for that i want to use the id coming from the API.
Here is my API Response: [/infos]
[
...
{
"id": 7,
"name": "Highway",
"price": "High",
"min": "785",
"max": "1856",
"tag": null,
},
{
"id": 8,
"name": "Lowway",
"price": "low",
"min": "685",
"max": "1956",
"tag": null,
}
...
]
Here is my Component.vue:
<div class="vx-row">
<div class="vx-col w-full md:w-1/2 mb-base" v-for="info in infos" :key="info.id">
<vx-card>
<div class="header">
<div class="left">
<img src="./img/info_8_logo.png" alt=""/> <-- Hard coded value ie 8
<b>{{info.name}}</b>
</div>
<div class="right">
<vs-button @click="$router.push({name: 'letsCheck', params: {viewContentId: '8' }}).catch(err => {})">Explore</vs-button>
<-- Above as a Hard-coded value ie 8 -->
{{mes.this_is_showing_only_data_of_id8}}
</div>
</div>
</vx-card>
</div>
</div>
<script>
infos: [],
mes: []
...
created () {
this.$http.get('/infos')
.then((response) => { this.infos = response.data })
.catch((error) => { console.log(error) })
this.$http.get('/messages/8/tick') <-- Hard coded value
.then((response) => { this.mes = response.data })
.catch((error) => { console.log(error) })
}
</script>
As you can see my Component.vue, i am displaying 8 cards and every cards are displaying the same contents as i have hardcoded the id as 8. So i want to know how to use the id coming from the API response of /infos endpoint in HTML and also in other scripts.
Also to note that the id coming from the API is just a number, so i want to know how to convert it to a string. And then how it can be used in other HTML and script.
Please help me in this i want to put the id coming from API to whichever comments i have made in Component.vue.