菜鸟自己做了个TodoMVC

想做个后台,就整个todoMVC,

手贱,想自己动手实现,发现后面还有一些没完成,看来,我应该不适合写代码

  1 <template>
  2   <div class="todo-content">
  3     <div class="todo-head">
  4       <h4>TODOMVC </h4>
  5       <el-input ref="closeTodo" v-model="todo" clearable prefix-icon="el-icon-arrow-down" placeholder="今天要做点什么呢"
  6                 @keydown.enter.native="addTodo"/>
  7     </div>
  8     <div class="todo-main">
  9       <ul>
 10         <li v-for="(item,index) in todoList" :key="index" @mousemove="closeShow(index)" @mouseleave="closeHidden">
 11           <el-switch
 12               inactive-color="#13ce66"
 13               active-color="#DCDFE6"
 14               v-model=item.Completed
 15               @change="changeCompleted(index)"
 16               class="switch"
 17           />
 18           <div class="title">
 19             <input :value="item.title" class="title-input" disabled="disabled"
 20                    :class="item.Completed ? 'title-delete':''"/>
 21           </div>
 22           <div class="close-title" v-show="active === index ? 'showIcon':''" @click="deleteTodo(index)">
 23             <i class="el-icon-close"></i>
 24           </div>
 25         </li>
 26       </ul>
 27     </div>
 28     <div class="todo-foot">
 29       <div class="item-index">
 30         <strong>{{ itemIndex }}</strong>
 31         <span>items left</span>
 32       </div>
 33       <div class="item-filter">
 34         <ul>
 35           <li style="border: 1px solid #e6e6e6;">
 36             All
 37           </li>
 38           <li>
 39             Active
 40           </li>
 41           <li>
 42             Completed
 43           </li>
 44         </ul>
 45       </div>
 46     </div>
 47   </div>
 48 </template>
 49 
 50 <script>
 51 export default {
 52   name: "TodoMVC",
 53   data() {
 54     return {
 55       todo: '',
 56       todoList: [],
 57       active: -1,
 58       showIcon: true
 59     }
 60   },
 61   computed: {
 62     itemIndex() {
 63       let todoArr = this.todoList
 64       let items = 0
 65       for (let i = 0; i < todoArr.length; i++) {
 66         if (todoArr[i].Completed === false) {
 67           items++
 68         }
 69       }
 70       return items
 71     }
 72   },
 73   methods: {
 74     addTodo() {
 75       if (this.todo === '') {
 76         return;
 77       } else {
 78         this.todoList = this.todoList.concat({
 79           title: this.todo,
 80           Completed: false
 81         })
 82       }
 83       this.todo = ''
 84       window.localStorage.setItem('content', JSON.stringify(this.todoList))
 85     },
 86     closeShow(index) {
 87       this.active = index
 88     },
 89     closeHidden() {
 90       this.active = -1
 91     },
 92     deleteTodo(index) {
 93       this.todoList.splice(index, 1)
 94       window.localStorage.setItem("content", JSON.stringify(this.todoList))
 95     },
 96     changeCompleted(index) {
 97       this.todoList.map(()=>{
 98         let _todoList = JSON.parse(localStorage.getItem('content'))
 99         _todoList[index].Completed = !_todoList[index].Completed
100         this.todoList = _todoList
101       })
102       window.localStorage.setItem("content", JSON.stringify(this.todoList))
103       // console.log(this.todoList)
104     },
105   },
106   created() {
107     if (!localStorage.getItem('content')) {
108       window.localStorage.setItem('content', JSON.stringify([{"title": "陶狗狗", "Completed": false}, {
109         "title": "我喜欢你",
110         "Completed": false
111       }, {"title": "我要给你生猴子", "Completed": true}, {"title": "你不配", "Completed": false}, {
112         "title": "他不配",
113         "Completed": false
114       }]))
115     }
116     this.todoList = JSON.parse(localStorage.getItem('content'))
117     // console.log(this.todoList)
118   }
119 }
120 
121 </script>
122 
123 <style lang="scss" scoped>
124 .todo-content {
125   background: #ffffff;
126   margin-top: 40px;
127 
128   .todo-head {
129     box-shadow: inset 0 -2px 1px rgba(0, 0, 0, 0.03);
130   }
131 
132   .todo-main {
133     ul {
134       list-style: none;
135       padding: 0;
136       margin: 0;
137 
138       li {
139         width: 100%;
140         font-size: 20px;
141         font-weight: 300;
142         padding: 10px 0px;
143         border-bottom: 1px solid #ededed;
144         display: flex;
145         justify-content: space-around;
146         align-items: center;
147 
148         .switch {
149           margin-left: 20px;
150           flex: 1;
151         }
152 
153         .title {
154           width: 50%;
155           flex: 6;
156           margin-left: 20px;
157 
158           .title-input {
159             width: 80%;
160             border: none;
161             color: #4d4d4d;
162             font-size: 16px;
163             font-weight: 300;
164             background: #fff;
165           }
166         }
167 
168         .close-title {
169           flex: 1;
170           display: flex;
171           align-items: center;
172           margin-right: 20px;
173           color: #cc9a9a;
174         }
175       }
176     }
177   }
178 
179   .todo-foot {
180     display: flex;
181     align-items: center;
182     color: #777;
183     font-weight: 400;
184     font-size: 12px;
185     box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2), 0 8px 0 -3px #f6f6f6, 0 9px 1px -3px rgba(0, 0, 0, 0.2), 0 16px 0 -6px #f6f6f6, 0 17px 2px -6px rgba(0, 0, 0, 0.2);
186 
187     .item-index {
188       margin-left: 5px;
189       margin-right: 10px;
190       padding: 3px 5px;
191 
192       span {
193         margin-left: 3px;
194       }
195     }
196 
197     .item-filter {
198       ul {
199         display: flex;
200         align-items: center;
201         list-style: none;
202         padding: 0;
203 
204         li {
205           margin-left: 15px;
206           padding: 3px 5px;
207         }
208       }
209     }
210   }
211 }
212 
213 .title-delete {
214   color: #d9d9d9 !important;
215   text-decoration: line-through;
216   transition: 0.5s;
217 }
218 
219 </style>
TodoMVC

 

posted @ 2020-10-28 22:05  xinyanwa  阅读(141)  评论(0编辑  收藏  举报