这篇“Vue怎么制作Todo List网页”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“Vue怎么制作Todo List网页”文章吧。
以下是HTML部分
<div class="main"> <h4 class="big-title">添加任务:</h4> <input placeholder="在此添加任务" class="task-input" type="text" v-model="things" @keyup.enter="addTodo" /> <ul class="task-count" v-show="list.length"> <li> {{unCheckedLength}}个任务未完成</li> <li class="action"> <a :class="{active: visibility == 'all'}" href="#all" rel="external nofollow" >所有任务</a> <a :class="{active: visibility == 'unfinished'}"href="#unfinished" rel="external nofollow" >未完成任务</a> <a :class="{active: visibility == 'finished'}"href="#finished" rel="external nofollow" >完成任务</a> </li> </ul> <div class="tasks"> <span class="no-task-tip" v-show="!list.length">还没有添加任何任务</span> <ul class="todo-list"> <li class="todo" v-for="item in filteredList" :class="{completed: item.isChecked,editing:item === editItem}" > <div class="view"> <div class="word"> <input class="toggle" type="checkbox" v-model="item.isChecked" > <label @dblclick="editTodo(item)">{{item.title}}</label> </div> <button class="destroy" type="text" @click="deleteTodo(item)">×</button> </div> <input v-focus="editItem === item" class="edit" type="text" v-model="item.title" @blur="edited" @keyup.enter="edited" @keyup.esc="cancel(item)" /> </li> </ul> </div> </div>
Vue实例部分
var vm = new Vue({ el: ".main", data: { list:list, things:"", editItem:"", beforeTitle:"", visibility:"all", inputId:"", }, watch:{ list:{ handler:function(){ store.save("todolist",this.list) }, deep:true } }, computed:{ unCheckedLength(){ return this.list.filter(function(item){ return item.isChecked == false }).length }, filteredList(){ return filter[this.visibility] ? filter[this.visibility](this.list) : list } }, methods: { addTodo(ev){ if(this.things !== ""){ var item = { title:this.things, isChecked:false, } this.list.push(item) } this.things = ""; }, deleteTodo(item){ var index = this.list.indexOf(item); this.list.splice(index,1); }, editTodo(item){ this.beforeTitle = item.title; this.editItem = item }, edited(item){ this.editItem = "" }, cancel(item){ item.title = this.beforeTitle; this.editItem = ""; this.beforeTitle = "" } }, directives:{ "focus":{ update(el,binding){ if(binding.value){ el.focus() } } } } });
这是一个基本的Vue实例,el是和DOM元素连接的挂载点,data是代理数据,在DOM的内容中如果要用到代理数据就用{{xxx}}表示,比如{{list}},{{visibility}},而当data中的代理数据出现在DOM标签里的时候就不需要用花括号。
new Vue({ el: ".main", data: { list:list, things:"", editItem:"", beforeTitle:"", visibility:"all", inputId:"", } })
Vue要用大的方法都放在methods部分
methods: { addTodo(ev){ if(this.things !== ""){ var item = { title:this.things, isChecked:false, } this.list.push(item) } this.things = ""; }, deleteTodo(item){ var index = this.list.indexOf(item); this.list.splice(index,1); }, editTodo(item){ this.beforeTitle = item.title; this.editItem = item }, edited(item){ this.editItem = "" }, cancel(item){ item.title = this.beforeTitle; this.editItem = ""; this.beforeTitle = "" } }
还有计算属性
computed:{ unCheckedLength(){ return this.list.filter(function(item){ return item.isChecked == false }).length }, filteredList(){ return filter[this.visibility] ? filter[this.visibility](this.list) : list } }
观察属性
watch:{ list:{ handler:function(){ store.save("todolist",this.list) }, deep:true } }
自定义属性
directives:{ "focus":{ update(el,binding){ if(binding.value){ el.focus() } } } }
以上就是关于“Vue怎么制作Todo List网页”这篇文章的内容,相信大家都有了一定的了解,希望小编分享的内容对大家有帮助,若想了解更多相关的知识内容,请关注亿速云行业资讯频道。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。