I dont know why my data wont show in my datatable but when I check the console and the vue tool i can see my data. When I compile my js files it wont show me an error. Im just using the datatable and used $('#example').DataTable();
function then i used v-for
in the <td>
for showing the data. Thanks for the help!
Users.vue
<table id="example" class="table table-striped table-bordered">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Email</th>
<th>Type</th>
<th>Created</th>
</tr>
</thead>
<tbody>
<tr v-for="user in users.data" :key="user.id">
<td>{{user.id}}</td>
<td>{{user.name}}</td>
<td>{{user.email}}</td>
<td>{{user.type}}</td>
<td>{{user.created_at}}</td>
</tr>
</tbody>
</table>
<script>
export default {
data() {
return {
editmode: false,
users: {},
form: new Form({
id:'',
name: "",
email: "",
password: "",
type: "",
})
};
},
methods: {
loadUsers(){
axios.get("api/user").then(({ data }) => (this.users = data));
}
},
created() {
console.log('Component mounted.')
this.loadUsers()
}
}
$(document).ready(function() {
$('#example').DataTable();
} );
</script>
app.js
require('./bootstrap');
import Vue from 'vue'
import { Form, HasError, AlertError } from 'vform'
import VueRouter from 'vue-router'
window.Vue = require('vue');
window.Form = Form;
Vue.use(VueRouter)
const routes = [
{ path: '/users', component: require('./components/Users.vue').default },
// { path: '*', component: require('./components/NotFound.vue').default}
]
const router = new VueRouter({
mode: 'history',
routes
})
Vue.component('users', require('./components/Users.vue').default);
const app = new Vue({
el: '#app',
router
});
api.php
Route::apiResource('user', 'API\UserController');
UserController.php
<?php
namespace App\Http\Controllers\API;
use App\igration;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\User;
class UserController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return User::all();
}
}