I start with vueJs and Webpack and I want to use vue router to create routes for elements of my table.
First i have the code of my table :
<table class="table table-condensed">
<tr style="text-align:left;" v-for="data in metadata">
<td>{{data.id}}</td>
<td><router-link :to="{ name: 'mixtapesDetails'}">
{{data.title}}
</router-link></td>
<td><router-link :to="{ name: 'mixtapesDetails'}">
{{data.artist}}
</router-link></td>
</tr>
</table>
Then i have my Js function to get all my data :
export default {
data(){
return {
metadata: null
}
},
methods:{
httpGet(theUrl){
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", theUrl, false); // true for asynchronous request
xmlHttp.send(null);
console.log(JSON.parse(xmlHttp.responseText));
return JSON.parse(xmlHttp.responseText);
}
},
mounted(){
this.metadata = this.httpGet("urltooJsondata");
}
}
And then i have my routes in JS :
export default new VueRouter({
routes: [
{
path: '/mixtapeList',
name: 'mixtapeList',
component: mixtapeList
},
{
path: '/mixtapesDetails/:id',
name: 'mixtapesDetails',
component: mixtapesDetails
}
]
})
The objectif is that when i click on a router-link it goes to a single page with a url like this /mixtapesdetails/id. But the difficult part is that i want the id = {{this.data.id}}. Sorry for my english, I really need help and i don't find the solution on web.