一劣像、新增數(shù)據(jù)
1要尔、輸入框
第一層用section,class="todoapp"
第二層用header元素歌豺,class="header"
第三層用input元素,class="new-todo"
input輸入框中設(shè)置數(shù)據(jù)雙向綁定v-model="newTodo"心包;設(shè)置綁定行為@keyup.enter="addTodo"
2类咧、列表顯示欄
第二層用section,class="main"
第三層用<ul>元素蟹腾,class="todo-list"
第四層用<li>元素痕惋,class="todo" ;用v-for="todo in todos"循環(huán)顯示數(shù)據(jù)娃殖。{{todo.title}}渲染數(shù)據(jù)
3值戳、實例設(shè)置
el='.todoapp' ;el定位最外圍section的todoapp類
data:{newTodo:''}炉爆;定義input雙向綁定newTodo為空
data:{todos:[ ]}堕虹;定義todos為數(shù)組
methods:{addTodo(){}}卧晓;定義方法,
1)獲取newTodo數(shù)據(jù):var value=this.newTodo
2)添加到todos數(shù)組內(nèi),默認任務(wù)完成狀態(tài)是false:this.todos.push({title:value,completed:false})
3)添加數(shù)組成功后清空input數(shù)據(jù):this.newTodo=' '
4赴捞、設(shè)置CSS更改外觀
html,
body {
margin: 0;
padding: 0;
font: 14px 'Helvetica Neue', Helvetica, Arial, sans-serif;
line-height: 1.4em;
background: #f5f5f5;
color: #4d4d4d;
min-width: 230px;
max-width: 550px; /*最寬*/
margin: 0 auto; /*居中*/
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
font-weight: 100; /*400 等同于 normal逼裆,而 700 等同于 bold*/
}
.todoapp {
background: #fff;
margin: 130px 0 40px 0; /*內(nèi)上距留130px;內(nèi)下距留40px*/
position: relative;
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2),
0 25px 50px 0 rgba(0, 0, 0, 0.1);
}
.todoapp h1 {
position: absolute; /**/
top: -155px; /*todo下面留25px*/
width: 100%;
font-size: 100px;
font-weight: 100;
text-align: center;
color: rgba(175, 47, 47, 0.15);
-webkit-text-rendering: optimizeLegibility;
-moz-text-rendering: optimizeLegibility;
text-rendering: optimizeLegibility;
}
.todoapp input::-webkit-input-placeholder {
font-style: italic;
font-weight: 300;
color: #e6e6e6;
}
.todoapp input::input-placeholder {
font-style: italic;
font-weight: 300;
color: #e6e6e6;
}
.new-todo {
position: relative;
margin: 0;
width: 100%;
font-size: 24px;
font-family: inherit;
font-weight: inherit;
line-height: 1.4em;
border: 0;
color: inherit;
padding: 6px;
border: 1px solid #999;
box-shadow: inset 0 -1px 5px 0 rgba(0, 0, 0, 0.2);
box-sizing: border-box;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
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);
}