Vue實現(xiàn)todolist刪除功能
更新時間:2018年06月26日 14:29:00 作者:XiaopengRong
這篇文章主要介紹了Vue實現(xiàn)todolist刪除功能,,代碼簡單易懂,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下
代碼如下所示:
<div id="app"> <input v-model="inputValue"> <button @click="handleSumbit">提交</button> <todo-item v-for="(item,index) of list":key="index":content="item":index="index" @delete="handleDelete"></todo-item> </div>
子組件向父組件傳遞數(shù)據(jù)使用 this.$emit('delete',this.index)
該方法
<script > Vue.component('todo-item',{ props:["content",'index'], template:"<li @click='handleSubmit'>{{content}}{{index}}</li>", methods:{ handleSubmit:function () { this.$emit('delete',this.index) } } }) new Vue({ el:'#app', data:{ inputValue:'', list:[] }, methods:{ handleSumbit:function () { this.list.push(this.inputValue); this.inputValue=""; }, handleDelete:function (index) { this.list.splice(index,1) } } }) </script>
總結(jié)
以上所述是小編給大家介紹的Vue實現(xiàn)todolist刪除功能,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
您可能感興趣的文章:
- 使用VueCli3+TypeScript+Vuex一步步構(gòu)建todoList的方法
- 詳解vuex的簡單todolist例子
- webpack4手動搭建Vue開發(fā)環(huán)境實現(xiàn)todoList項目的方法
- vue實現(xiàn)todolist基本功能以及數(shù)據(jù)存儲功能實例詳解
- 使用Vue父子組件通信實現(xiàn)todolist的功能示例代碼
- Vue中父子組件通訊之todolist組件功能開發(fā)
- vue todo-list組件發(fā)布到npm上的方法
- vue組件編寫之todolist組件實例詳解
- 使用Vue完成一個簡單的todolist的方法
- Vue實現(xiàn)todo應(yīng)用的示例
相關(guān)文章
5個可以加速開發(fā)的VueUse函數(shù)庫(小結(jié))
VueUse為Vue開發(fā)人員提供了大量適用于Vue2和Vue3的基本Composition API 實用程序函數(shù)。具有一定的參考價值,感興趣的可以了解一下2021-11-11關(guān)于Vue中img動態(tài)拼接src圖片地址的問題
這篇文章主要介紹了關(guān)于Vue中img動態(tài)拼接src圖片地址的問題,本文通過實例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-10-10