My API consists of endpoints that return lists of JSON objects:
/api/data/foo
/api/data/bar
/api/data/fizz
In my single-page application, I have a table and a dropdown selector:
<select v-model="tableChoice">
<option selected>Foo</option>
<option>Bar</option>
<option>Fizz</option>
</select>
<table class="table table-hover">
<thead>
<tr>
<th v-for="header in tableHeaders">
{{ header }}
</th>
</tr>
</thead>
<tbody>
<tr v-for="record in tableData" :key="record.recordId">
<td v-for="element in record">{{element}}</td>
</tr>
</tbody>
</table>
I currently have three separate Vue components with their own API URLs and table headers:
var fooLink = 'api/foo';
new Vue({
el: '#app',
data: {
tableHeaders:["Record ID","Record Name", "Record Detail"],
tableData: null,
dataChoice: 'Foo'
},
methods:{
getFooData: function(){
this.$http.get(fooLink).then(function(response){
this.tableData = response.data;
}, function(error){
console.log(error.statusText);
});
}
},
mounted: function () {
this.getFooData();
}
});
I am looking to use a single table or component where the API URL used is determined by the tableChoice variable. How can I achieve this without clear documentation on conditional loading with props?