forked from sunseekers/Vue2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdome1.html
122 lines (121 loc) · 2.86 KB
/
dome1.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>综合练习</title>
<meta name="description" content="">
<meta name="keywords" content="">
<meta name='viewprot' content='width=device-width,minmum-scale=1.0,maxmum-scale=1.0'>
<style type="text/css">
div{
width:500px;
margin: 30px auto;
}
.edit{
display:block ;
line-height: 35px;
box-sizing: border-box;
padding-left: 20px;
border-radius: 4px;
border:1px solid #ccc;
box-shadow: 0 0 5px #ccc;
}
.task li{
position: relative;
padding: 10px 0;
border-bottom: 1px solid #efefef;
list-style: none;
}
.task li:last-child{
border-bottom: 0;
}
.finish{
text-decoration: line-through;
color: #ccc;
}
.del{
background: red;
text-decoration: none;
position: absolute;
right:0;
font-size: 12px;
border: 0;
outline: 0;
padding: 2px 5px;
border-radius: 5px;
color: #fff;
}
.empty{
font-size: 13px;
color: #000;
text-align: center;
padding: 10px 0;
}
</style>
</head>
<body>
<div id='app'>
<p>
用我们学过的指令 v-model @ v-if和 methods 创建一个 Vue 实例;
在输入框内输入数据,按下回车键,自动添加到页面中,点击删除,删除该指令;动手试试吧
</p>
<input type='text' placeholder='edit something '
class='edit' autofocus
v-model='items.content'
@keydown.enter='addTask'
>
<ul class='task'>
<li v-for='(item,index) in list' :key='index'>
<input @click='changeState(index)'
:checked='item.finished'
type='checkbox'>
<span :class="{'finish':item.finished}">{{item.content}}</span>
<button @click='removeList(index)' class='del'>删除</button>
</li>
</ul>
<p class='empty' v-if='list.length===0'>暂无内容</p>
</div>
</body>
<script type="text/javascript" src='js/vue.min.js'></script>
<script type="text/javascript">
var vm=new Vue({
el:'#app',
jjjj:'oooo',
data:{
//默认数据
items:
{
content: '',//初始化内容为空,不能省略
finished: false,//未完成
deleted: false//未删除
},
list:[]
},
//列表
methods:{
//es6 的写法
addTask(){
//将任务存入数组
this.list.push(this.items);
//重置 items
this.items={
content: '',//初始化内容为空,不能省略
finished: false,//未完成
deleted: false//未删除
}
},
//选中改变状态
changeState(index){
let curState=this.list[index].finished;
this.list[index].finished=!curState;
},
//删除
removeList(index){
this.list.splice(index,1);
}
}
})
console.log(vm.$options.jjjj);
</script>
</html>