<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="./vue.js"></script>
<style>
.green{
background-color: green;
}
.red{
background-color: red;
}
</style>
</head>
<body>
<div id="app">
<input
v-model='inputvalue'
type="text" name="" id="" placeholder="请输入要做的事">
<button @click='add'>添加</button>
<ul>
<li v-for='item,index in list'
v-bind:class='item.state?"green":"red"'
>{{item.event}}
<button @click='del(index)'>删除</button>
<span v-if='item.state'>已完成</span>
<button v-else
@click='finish(index)'
>待完成</button>
</li>
</ul>
</div>
<script >
let vm=new Vue({
el:'#app',
data:{
list:[{event:'今晚代码到天明',state:false},{event:'今晚代码到天明',state:false},{event:'今晚代码到天明',state:false},{event:'今晚代码到天明',state:false}],
inputvalue:'zx'
},
methods:{
add(){
this.list.push({event:this.inputvalue,state:false})
},
del(index){
this.list.splice(index,1)
},
finish(index){
this.list[index].state=true
}
}
})
</script>
</body>
</html>
|