使用Vue.js完成一个todo-list
使用Vue.js完成一个todo-list首先分析一下页面的组成,要与一个供输入的用户输入框,然后下面应该是个列表,这个列表是用户的输入的内容的展示页面结构:<div id="todo-list-emp"><input type="text" placeholder="Add a todo" v-model="newTodoText" v-on:keyup.enter="add
·
使用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)">
</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);
}
更多推荐
已为社区贡献9条内容
所有评论(0)