vue
2025-08-10 21:04:46
发布于:广东
<script setup>
import { ref, computed } from 'vue'
let id = 0
const newTodo = ref('')
const hideCompleted = ref(false)
const todos = ref([])
const filteredTodos = computed(() => {
return hideCompleted.value
? todos.value.filter((t) => !t.done)
: todos.value
})
function addTodo() {
todos.value.push({ id: id++, text: newTodo.value, done: false })
newTodo.value = ''
}
function removeTodo(todo) {
todos.value = todos.value.filter((t) => t !== todo)
}
</script>
<template>
<div class="box">
<form @submit.prevent="addTodo">
<input v-model="newTodo" required placeholder="new todo" class="box3" >
<button class="box1">确定</button>
</form>
<TransitionGroup tag="ul" name="fade" class="container">
<li v-for="todo in filteredTodos" :key="todo.id" class="box4">
<span class="box5"> //</span>
<span :class="{ done: todo.done }" class="box6">{{ todo.text }}</span>
<input type="checkbox" v-model="todo.done" >
<button @click="removeTodo(todo)" class="box2">X</button>
</li>
</TransitionGroup>
<button @click="hideCompleted = !hideCompleted" >
{{ hideCompleted ? 'Show all' : 'Hide completed' }}
</button>
</div>
</template>
<style>
.box6{
display: inline-flexbox;
}
.container {
position: relative;
padding: 0;
list-style-type: none;
}
.fade-move,
.fade-enter-active,
.fade-leave-active {
transition: all 0.3s cubic-bezier(0.55, 0, 0.1, 1);
background-color: #f0f0f1;
}
.fade-enter-from,
.fade-leave-to {
opacity: 0;
transform: scaleY(0.01) translate(30px, 0);
background-color: #f0f0f1;
}
.fade-leave-active {
position: absolute;
}
.box {
justify-content: center;
align-items: center;
min-height: 100vh;
padding: 20px;
background-color: #f0f0f1;
}
.box1{
color: white;
height: 25px;
background: linear-gradient(135deg, #669ee3 0%,#667ee1 30%, #764bf6 100%);
border-radius: 0px 5px 5px 0px;
}
.box2{
color: white;
background: red;
width:24px;
height: 20px;
display:flex-end;
}
.box3{
border-radius: 5px 0px 0px 5px;
width:80%;
height: 20px;
}
.box4{
margin-bottom: 15px;
background: white;
width:100%;
height: 30px;
border-radius: 5px;
display:flex-end;
}
.box5{
color:white;
}
.done {
color:red;
text-decoration: line-through;
}
</style>
这里空空如也
有帮助,赞一个