I am using jQuery data-table in Vue.js in a laravel project. the data has reloaded well in data-table. but the problem is the data retrieve after loading data-table. because, in the first row of data-table says "there is not any data"!! what should i do to use jQuery data-table in Vue.js?
app.js file:
export const platform= {
el:'#platform',
data: {
name:'',
platforms: [],
},
methods: {
index:function() {
axios.get('/api/platforms', {
headers: headers
}).then(response => {
this.platforms = response.data.data;
this.dataTable.row.add([
this.platforms
]);
}).catch(error => {
alert(error.response.data.message);
})
},
store:function() {
axios.post('/api/platforms', {
params: {
name: this.name
}
}, {
headers: headers
}).then(response => {
this.platforms.push(response.data.data);
alert(response.data.message);
}).catch(error => {
if (error.response.status === 422) {
this.message = error.response.data.data['validation-errors']['params.name'];
} else {
this.message = error.response.data.message;
}
})
},
},
mounted:function() {
this.index();
},
};
the platform.blade.php file:
<section class="content" id="platform">
<div class="form-group">
<input type="text" v-model="name">
</div>
<button class="btn btn-raised" @click.prevent="store()">save</button>
<div class="row">
<table class="table table-bordered table-striped table-hover dataTable">
<thead>
<tr>
<th>platform name</th>
</tr>
</thead>
<tbody>
<tr v-for="(platform, index) in platforms">
<td>@{{ platform.name }}</td>
</tr>
</tbody>
</table>
</div>
</section>