<div id="app">
<label>id</label>
<input type="text" v-model="id">
<label>name</label>
<input type="text" v-model="name">
<input type="button" v-on:click="add" value="btn">
<p v-for="item in list" :key=item.id >
<input type="checkbox">
{{item.name}}</p>
</div>
<script>
var app = new Vue({
el:'#app',
data:{
id : '',
name: '',
list: [
{id:0,name:"長安"},
{id:1,name:"長城"},
{id:2,name:"奔馳"},
{id:3,name:"寶馬"}
]
},
methods:{
add:function () {
this.list.push({list:this.id,name:this.name})
alert('yes');
}
}
})
</script>
複製代碼