葵花宝典

vuePress-theme-reco 前端小菜-贺俊兰    2026
葵花宝典 葵花宝典

Choose mode

  • 关灯
  • 自动
  • 开灯
主页
分类
  • LeetCode
  • JavaScript
  • Node
  • 其他
  • VUE
标签
时间轴
author-avatar

前端小菜-贺俊兰

33

文章

7

标签

主页
分类
  • LeetCode
  • JavaScript
  • Node
  • 其他
  • VUE
标签
时间轴
  • vue2

  • vue3

    • vue3初体验
    • vue3-todoMVC练习
    • vue3 + TS + Vite + Vuex4 + Element-Plus 创建项目

vue3-todoMVC练习

vuePress-theme-reco 前端小菜-贺俊兰    2026

vue3-todoMVC练习

前端小菜-贺俊兰 2020-08-25 VUE

# todoMVC 简介

链接

参照todeMVC网站,复制样式,做个类似的例子。打开NewWork,找到todomvc-app-css的index.css,放到本地就可以了。

# CODE

啥也别说了,上才艺

<template>
  <section class="todoapp">
    <header class="header">
      <h1>Vue3 todos</h1>
      <input class="new-todo" placeholder="想干的事" v-model="newTodo" @keyup.enter="addTodo" />
    </header>
    <section class="main">
      <input id="toggle-all" type="checkbox" class="toggle-all" />
      <label for="toggle-all">Mark all as complete</label>
      <ul class="todo-list">
        <li v-for="todo in todos" class="todo" :key="todo.id">
          <div class="view">
            <input type="checkbox" :value="todo.isCheck" class="toggle" />
            <label>{{todo.title}}</label>
            <button class="destroy" @click="removeTodo(todo)"></button>
          </div>
        </li>
      </ul>
    </section>
  </section>
</template>


<script>
import { reactive, toRefs } from "vue";
export default {
  setup() {
    const state = reactive({
      newTodo: "",
      todos: [{ id: 1, title: "练习", isCheck: false }],
    });

    function addTodo() {
      const value = state.newTodo && state.newTodo.trim();
      if (!value) return;
      state.todos.push({
        id: state.todos.length + 1,
        title: value,
        isCheck: false,
      });
      state.newTodo = "";
    }

    function removeTodo(item) {
      state.todos = state.todos.filter((empty) => empty.id != item.id);
    }

    return {
      ...toRefs(state),
      addTodo,
      removeTodo,
    };
  },
};
</script>
<style scoped>
.toggle {
  left: 0;
}
</style>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
欢迎来到 葵花宝典
看板娘