您好,登錄后才能下訂單哦!
這篇“Vue怎么制作Todo List網(wǎng)頁”文章的知識點大部分人都不太理解,所以小編給大家總結(jié)了以下內(nèi)容,內(nèi)容詳細,步驟清晰,具有一定的借鑒價值,希望大家閱讀完這篇文章能有所收獲,下面我們一起來看看這篇“Vue怎么制作Todo List網(wǎng)頁”文章吧。
以下是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是代理數(shù)據(jù),在DOM的內(nèi)容中如果要用到代理數(shù)據(jù)就用{{xxx}}表示,比如{{list}},{{visibility}},而當data中的代理數(shù)據(jù)出現(xiàn)在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() } } } }
以上就是關(guān)于“Vue怎么制作Todo List網(wǎng)頁”這篇文章的內(nèi)容,相信大家都有了一定的了解,希望小編分享的內(nèi)容對大家有幫助,若想了解更多相關(guān)的知識內(nèi)容,請關(guān)注億速云行業(yè)資訊頻道。
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。