課程
/前端開(kāi)發(fā)
/Vue.js
/vue2.5入門(mén)
不用組件拆分的方式,怎樣實(shí)現(xiàn)todolist功能?有哪位小伙伴試過(guò)嗎?分享一下代碼?
2019-09-21
源自:vue2.5入門(mén) 3-4
正在回答
<!DOCTYPE?html><html><head> <meta?charset="utf-8"> <title>todo</title> <script?type="text/javascript"?src="./vue.js"></script></head><body> <div?id="app"> <input?type="text"?v-model="event"> <button?@click="submit">提交</button> <!--?不使用組件?--> <ul> <li?v-for="(item,?index)?in?list"?:key="index"?:data-id="index"?@click="del">{{item}}</li>? </ul> <!--?使用全局組件?--> <!--?<ul> <todo-item-qj?v-for="(item,?index)?in?list"? :key="index"? :content="item"? :prex="index" @delete="handleDelete" > </todo-item-qj> </ul>?--> </div> <script?type="text/javascript"> //?全局組件 Vue.component('todo-item-qj',?{ props:?['content',?'prex'], template:?'<li?@click="handleClick">{{prex}}?-?{{content}}</li>', methods:?{ handleClick:?function(){ this.$emit('delete',?this.prex); } } }); //?局部組件 var?todoItem?=?{ props:?['content',?'prex'], template:?'<li>{{prex}}?-?{{content}}</li>', }; var?app?=?new?Vue({ el:?'#app', data:?{ event:?'', list:?[], }, methods:{ submit:?function(){ if(!this.event.length) { alert('輸入值'); } this.list.push(this.event); this.event?=?''; }, del:?function(event){ //?console.log(event.target.dataset.id); let?prex?=?event.target.dataset.id; this.list.splice(prex,?1); }, handleDelete:?function(prex)?{ //?alert(prex); this.list.splice(prex,?1); }, } }); </script></body></html>
https://github.com/WadeStack/vue
舉報(bào)
快速理解Vue編程理念上手Vue2.0開(kāi)發(fā)。
5 回答使用了組件后做的todolist再怎么實(shí)現(xiàn)刪除每項(xiàng)功能呢?
1 回答組件的拆分中item內(nèi)容的問(wèn)題
2 回答todoList的刪除功能的問(wèn)題
1 回答todolist組件顯示問(wèn)題
2 回答拆分組件里面接收content的屬性名可以任意寫(xiě)還是只能用props?
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢(xún)優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2020-05-30
2019-09-22
https://github.com/WadeStack/vue