Well, i am new to vuejs and i am working on a project where every data/contents is taken from the RestAPI. So, now i want to make my components completely dynamic without any hard-coding and just use the id coming from the API and display the contents accordingly.
Here is my router.js:
{
path: '/views/frames',
name: 'frames',
component: () => import('./views/frames/App.vue'),
},
{
path: '/views/frames/:viewContentId', <--- Dynamic routing
name: 'letsCheck',
component: () => import('./views/frames/Contents.vue')
}
Here is my App.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>
Currently from these following codes i am displaying 8 cards in the first page, which gets the same contents of the id=8 as i have hard coded it in App.vue ie (mes). But i want to make it dynamic without using any of the ids directly, rather the code should use the id which is coming from the API /infos and then display contents accordingly.
And when button is clicked in the App.vue, suppose say user have clicked it in 3rd card, then the components.vue must assign id=3 and display the contents.
Please help me in this I'm stuck here!