I am learning VueJS and using it with laravel 5.4. I am familiar with laravel. The problem I am having is displaying data from database in Vue components. Data is being retrieved successfully from the server. I cannot see this when I print retrieved data in the browser console. But it cannot be displayed in the view. the v-for directive is running just fine and I can see the edit button accompanied by each raw printed on each loop. However values from data base are blank. Here is my displayCategory.vue component.
<template>
<div>
<h3>Orders</h3>
<div class="row">
<div class="col-md-10"></div>
<div class="col-md-2">
<router-link :to="{ name: 'create-product-category'}" class="btn btn-primary">Add Category</router-link>
</div>
</div><br />
<table class="table table-hover table-striped table-responsive">
<thead>
<tr>
<td>Category Name</td>
<td>Description</td>
<td>Actions</td>
</tr>
</thead>
<tbody>
<tr v-for="category in categories">
<td>{{ category.category_name }}</td>
<td>{{ category.description }}</td>
td><router-link :to="{name: 'edit-product-category', params: { id: category.id }}" class="btn btn-primary">Edit</router-link></td>
<td><button class="btn btn-danger" v-on:click="deleteCategory(category.id)">Delete</button></td>
</tr>
</tbody>
</table>
</div>
</template>
<script>
export default {
name:'list-product-categories',
data(){
return{
categories: []
}
},
created: function()
{
this.fetchCategories();
},
methods: {
fetchCategories()
{
let uri = '/api/product/categories';
this.axios.get(uri).then((response) => {
this.categories = response.data;
console.log(this.categories);
});
},
deleteCategory(id)
{
let uri = 'http://localhost/dms/public/api/products/categories/${id}';
this.categories.splice(id, 1);
this.axios.delete(uri);
}
}
}
</script>
Other areas of the app is working normally as I can save records to the server and load input form components. Please assist.
td><router-link ..