I am trying to make a sort table in Laravel using Vue.js. I tried some solutions on the internet, but it still doesn't work for me.
Here is my template file:
<template>
<div class="container">
<table class="table table-bordered">
<thead>
<tr>
<th v-for="column in columns">{{ column }}</th>
</tr>
</thead>
<tbody>
<tr v-for="(emp, key) in emp">
<td>{{ emp.id }}</td>
<td>{{ emp.emp_name }}</td>
<td>{{ emp.salary }}</td>
<td>{{ emp.phone_number }}</td>
</tr>
</tbody>
</table>
</div>
</template>
My script file:
<script>
export default {
data() {
return {
emp: [],
columns: ['No','Name', 'Salary', 'Phone Number']
}
},
mounted() {
this.fetchUser();
},
methods: {
fetchUser(){
fetch('api/employee').then(res => res.json())
.then(res => {
this.emp = res.data;
console.log(res);
})
},
}
}
</script>
I'll appreciate of all your help. Thanks in advance..
sort table<div v-if="reverseList"> {{ reverseList }} </div><button v-on:click="reverseList">Reverse list</button>methods: { reverseList() { return emp.reverse(); } }