Vue TodoList 解析 1.新增条目

一、新增数据

1、输入框

第一层用section,class="todoapp"
第二层用header元素,class="header"
第三层用input元素,class="new-todo"
input输入框中设置数据双向绑定v-model="newTodo";设置绑定行为@keyup.enter="addTodo"

2、列表显示栏

第二层用section,class="main"
第三层用<ul>元素,class="todo-list"
第四层用<li>元素,class="todo" ;用v-for="todo in todos"循环显示数据。{{todo.title}}渲染数据

定义输入框和列表框
3、实例设置

el='.todoapp' ;el定位最外围section的todoapp类
data:{newTodo:''};定义input双向绑定newTodo为空
data:{todos:[ ]};定义todos为数组
methods:{addTodo(){}};定义方法,
1)获取newTodo数据:var value=this.newTodo
2)添加到todos数组内,默认任务完成状态是false:this.todos.push({title:value,completed:false})
3)添加数组成功后清空input数据:this.newTodo=' '


2017-12-06 14-55-01屏幕截图.png
效果图
4、设置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;  /*内上距留130px;内下距留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);
}
效果图
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。