您的位置:首页 > 产品设计 > UI/UE

使用Vue.js完成一个todo-list

2017-05-11 16:52 686 查看

使用Vue.js完成一个todo-list

首先分析一下页面的组成,要与一个供输入的用户输入框,然后下面应该是个列表,这个列表是用户的输入的内容的展示

页面结构:

<div id="todo-list-emp">
<input type="text" placeholder="Add a todo" v-model="newTodoText" v-on:keyup.enter="addNewTodo">
<ul>
<li is="todo-item" v-for="(todo, index) in todos" v-bind:title="todo" v-on:remove="todos.splice(index, 1)"><
4000
/span>
</li>
</ul>
</div>


JavaScript部分:

Vue.component('todo-item', {
template : '<li>{{ title }}<button v-on:click="$emit(\'remove\')">X</button></li>',
props: ['title']
});
new Vue({
el : "#todo-list-emp",
data : {
newTodoText : '',
todos : [
'Do the dishes',
'Take out the trash',
'Mow the lawn'
]
},
methods: {
addNewTodo : function() {
this.todos.push(this.newTodoText);
this.newTodoText = '';
}
}
});


基本的样式:

input {
width: 300px;
height: 30px;
border: 2px solid #DDDDDD;
border-radius: 5px;
font-size: 16px;
color: rgba(0, 0, 0, 0.6);
text-align: center;
}
input:hover {
border: 2.5px solid #42B983;
color: rgba(0, 0, 0, 0.7);
}
ul {
padding: 0;
margin-top: 15px;
}
ul li {
width: 300px;
height: 40px;
line-height: 40px;
color: rgba(0, 0, 50, 0.8);
font-size: 22px;
font-family: 'Lato', Calibri, Arial, sans-serif;
list-style: none;
border: 1px solid #333333;
border-radius: 5px;
text-align: center;
}
ul li + li {
margin-top: 1px;
}
li button {
font-size: 8px;
line-height: 14px;
background: #fff;
border: 0;
float: right;
margin-right: 3px;
color: rgba(0, 0, 0, 0.9);
}


代码下载链接:http://download.csdn.net/detail/dear_mr/9839795
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: