Vue之TodoList案例詳解
<template> <div id="root"> <div class="todo-container"> <div class="todo-wrap"> <Top :received="received" /> <List :todos="todos" :checkTodo="checkTodo" :deleteTodo="deleteTodo" /> <Bottom :todos="todos" :checkAllTodo="checkAllTodo" :clearAllTodo="clearAllTodo" /> </div> </div> </div> </template> <script> import Top from './components/Top.vue' import Bottom from './components/Bottom.vue' import List from './components/List.vue' export default { name: 'App', components: { Top, List, Bottom }, data() { return { todos: [{ id: '001', title: '吃飯', done: true }, { id: '002', title: '睡覺(jué)', done: false }, { id: '003', title: '打豆豆', done: false }, ] } }, methods: { //添加一個(gè)todo received(todoObj) { this.todos.unshift(todoObj); }, //取消勾選todo checkTodo(id) { this.todos.forEach((todo) => { //函數(shù)體 if (todo.id === id) todo.done = !todo.done; }) }, //刪除 deleteTodo(id) { this.todos = this.todos.filter(todo => todo.id !== id) }, //全選 全不選 checkAllTodo(done) { this.todos.forEach((todo) => { todo.done = done }) }, //清除所有已經(jīng)完成的數(shù)據(jù) clearAllTodo() { this.todos = this.todos.filter((todo) => { return !todo.done }) } } } </script> <style lang="css"> /*base*/ body { background: #fff; } .btn { display: inline-block; padding: 4px 12px; margin-bottom: 0; font-size: 14px; line-height: 20px; text-align: center; vertical-align: middle; cursor: pointer; box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05); border-radius: 4px; } .btn-danger { color: #fff; background-color: #da4f49; border: 1px solid #bd362f; } .btn-danger:hover { color: #fff; background-color: #bd362f; } .btn:focus { outline: none; } .todo-container { width: 600px; margin: 0 auto; } .todo-container .todo-wrap { padding: 10px; border: 1px solid #ddd; border-radius: 5px; } </style>
總結(jié)
本篇文章就到這里了,希望能夠給你帶來(lái)幫助,也希望您能夠多多關(guān)注腳本之家的更多內(nèi)容!
相關(guān)文章
vue-router動(dòng)態(tài)設(shè)置頁(yè)面title的實(shí)例講解
今天小編就為大家分享一篇vue-router動(dòng)態(tài)設(shè)置頁(yè)面title的實(shí)例講解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-08-08vue項(xiàng)目中的遇錯(cuò):Invalid?Host?header問(wèn)題
這篇文章主要介紹了vue項(xiàng)目中的遇錯(cuò):Invalid?Host?header問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-07-07vue使用vuedraggable實(shí)現(xiàn)嵌套多層拖拽排序功能
這篇文章主要為大家詳細(xì)介紹了vue使用vuedraggable實(shí)現(xiàn)嵌套多層拖拽排序功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-04-04淺析Vue中Virtual?DOM和Diff原理及實(shí)現(xiàn)
這篇文章主要為大家詳細(xì)介紹了Vue中Virtual?DOM和Diff原理及實(shí)現(xiàn)的相關(guān)知識(shí),文中的示例代碼講解詳細(xì),感興趣的小伙伴可以了解一下2023-03-03如何解決el-checkbox選中狀態(tài)更改問(wèn)題
這篇文章主要介紹了如何解決el-checkbox選中狀態(tài)更改問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-07-07vue element 關(guān)閉當(dāng)前tab 跳轉(zhuǎn)到上一路由操作
這篇文章主要介紹了vue element 關(guān)閉當(dāng)前tab 跳轉(zhuǎn)到上一路由操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-07-07Vue項(xiàng)目webpack打包部署到服務(wù)器的實(shí)例詳解
這篇文章主要介紹了Vue項(xiàng)目webpack打包部署到服務(wù)器的實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下2017-07-07VUE異步更新DOM - 用$nextTick解決DOM視圖的問(wèn)題
這篇文章主要介紹了VUE異步更新DOM - 用$nextTick解決DOM視圖的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-11-11詳解Vue調(diào)用手機(jī)相機(jī)和相冊(cè)以及上傳
這篇文章主要介紹了Vue調(diào)用手機(jī)相機(jī)及上傳,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-05-05