<div id="app">
<input type="text" v-model="keyword" @keyup="handleInput">
<h1>进行中 <span>{{lists.length-isEnd}}</span></h1>
<div v-for="(item,index) of lists">
<p v-if="!item.checked"><input type="checkbox" v-model="item.checked">
<span>{{item.val}}</span>
<button>删除</button>
</p>
</div>
<h1>已完成 {{isEnd}}</h1>
<div v-for="(item,index) of lists">
<p v-if="item.checked"><input type="checkbox" v-model="item.checked">
<span>{{item.val}}</span>
<button>删除</button>
</p>
</div>
</div>
<script>
new Vue({
el:"#app",
data(){
return {
keyword:"",
lists:[],
isEnd:""
}
},
methods:{
handleInput(event){
if(event.keyCode == 13){
var keyword = this.keyword;
this.lists.push({val:keyword,checked:false})
this.keyword= ""
}
}
},
watch:{
lists:{
handler(val){
var newList = val.filter(item=>{
return item.checked
})
console.log(newList)
this.isEnd = newList.length
},
deep:true
}
}
})
</script>