I want to add the data into table when I want to. However, I can not add the data after initializing the vue instances.
I have tried to use followings, but, still dose not update data.
・$nextTick ・$set
<script>
var overall = new Vue({
el: '#overall',
data: {
headers:[
"no","name",'gender'
],
items: []
}, methods: {
add: function(item)
{
this.items = item;
}
}
});
overall.add([{no:'1',name:'Tom Tom',gender:'male'}]);
</script>
<div id="overall">
<table>
<thead> <tr>
<th v-for="header in headers">
{{header}}
</th>
</tr>
</thead>
<tbody >
<tr v-if="items.length === 0"> <td>No data</td> </tr> <tr v-else v-for="item in items">
<td>{{item.no}}</td>
<td>{{item.name}}</td>
<td>{{item.gender}}</td>
</tr>
</tbody>
</table>
</div>
addfunction is assigning an item tothis.items, i dont know what youre doing here.this.items = item;should rather bethis.items.push(item);addneeds topush, 2)tbodytrneeds av-for, 3)addshould be defined in Vue app'smethodsobject, 4)addshould be called increatedlifecycle hook, not outside the app