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 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
| <!DOCTYPE html> <html lang="zh-CN">
<head> <meta charset="UTF-8"> <title>todolist</title> <style type="text/css"> * { margin: 0; padding: 0; box-sizing: border-box; }
body { background-color: #f5f5f5; color: #444 }
a { text-decoration: none; color: #333; }
#app { width: 640px; margin: 0 auto }
#app h1 { text-align: center; font-size: 5em; color: rgba(175, 47, 47, 0.15); }
.todoapp { min-height: 200px; background: #fff; margin: 30px 0 40px 0; position: relative; box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2), 0 25px 50px 0 rgba(0, 0, 0, 0.1); padding-bottom: 40px; }
/*.todoapp:before{content: '';}*/ .header { position: relative; }
.new-todo { padding: 16px 16px 16px 60px; border: none; background: rgba(0, 0, 0, 0.003); box-shadow: inset 0 -2px 1px rgba(0, 0, 0, 0.03); width: 100%; font-size: 24px; }
:focus { outline: 0; }
.toggle-all { background: none; position: absolute; top: 19px; left: -6px; width: 60px; height: 34px; text-align: center; border: none; -webkit-appearance: none; cursor: pointer; }
.toggle-all:before { content: '﹀'; font-size: 22px; color: #333; padding: 10px 27px 10px 27px; }
.todolist li { padding: 10px; border-bottom: 1px solid #e6e6e6; list-style: none; }
.todolist li input, .todolist li a { display: inline-block; width: 45px; }
.todolist li input { height: 25px; vertical-align: -5px; }
.todolist li a { float: right; display: none; font-size: 20px }
.todolist li:hover a { color: #af5b5e; display: block; }
.todolist li span { font-size: 1.5em; }
.todolist li:last-child { border-bottom: none; }
.footer { color: #777; padding: 10px 15px; height: 40px; position: absolute; width: 100%; bottom: 0; border-top: 1px solid #e6e6e6; }
.footer:before { content: ''; position: absolute; right: 0; bottom: 0; left: 0; height: 50px; overflow: hidden; box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2), 0 8px 0 -3px #f6f6f6, 0 9px 1px -3px rgba(0, 0, 0, 0.2), 0 16px 0 -6px #f6f6f6, 0 17px 2px -6px rgba(0, 0, 0, 0.2); }
.clear-completed { float: right; position: absolute; right: 20px; }
/*事项完成时*/ .completed { color: #d9d9d9; text-decoration: line-through; } .red{ color: #f00; } </style> <script src="vue.v2.6.12.js"></script> </head>
<body> <!-- 外观参考了:http://todomvc.com/examples/vue/ 代码By 罗永超 --> <div id="app"> <h1>todolist</h1> <section class="todoapp"> <header class="header"> <input autofocus="autofocus" autocomplete="off" placeholder="请在这里输入您的待办事项" v-model="text" class="new-todo" @keyup.enter="add"> <input type="checkbox" class="toggle-all" v-model="checkall"> </header> <ul class="todolist"> <li v-for="item,index in list"> <input type="checkbox" v-model="item.check"> <span :class="{completed:item.check==true}">{{item.content}}</span> <a href="#" @click="del(index)">x</a> </li> </ul> <footer class="footer"> <span class="todo-count"><strong :class="{red:todo>0}">{{todo}}</strong> 个未完成 </span> <a class="clear-completed" href="#" @click="clear"> 清除已完成 </a> </footer> </section> </div> <script> let vm = new Vue({ el: "#app", data: { list: [], text: ""//输入框文本 }, methods: { add() {//回车新增待办 if(!this.text){return};//判断非空 this.list.unshift({check:false,content:this.text});//数组中添加对象 this.text = "";//输入框文本清空 }, del(index){//删除单个 this.list.splice(index,1); }, clear(){//删除全部 this.list=this.list.filter(item=>item.check==false); } }, computed: { checkall: { get() {}, set(value) { this.list.forEach(item=>{item.check=value});//全选绑定 } }, todo(){ return this.list.filter(item=>item.check==false).length;//未完成计数 } } }) </script> </body>
</html>
|