您好,登錄后才能下訂單哦!
小編給大家分享一下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: '睡覺', done: false }, { id: '003', title: '打豆豆', done: false }, ] } }, methods: { //添加一個todo received(todoObj) { this.todos.unshift(todoObj); }, //取消勾選todo checkTodo(id) { this.todos.forEach((todo) => { //函數體 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 }) }, //清除所有已經完成的數據 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>
以上是“Vue中TodoList的示例分析”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。