Vue TodoList 解析 1.新增條目

一、新增數(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),默認(rèn)任務(wù)完成狀態(tài)是false:this.todos.push({title:value,completed:false})
3)添加數(shù)組成功后清空input數(shù)據(jù):this.newTodo=' '


2017-12-06 14-55-01屏幕截圖.png
效果圖
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);
}
效果圖
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容