mirror of
https://github.com/Dichgrem/Vue.git
synced 2025-12-16 21:51:59 -05:00
style:fmt
This commit is contained in:
@@ -1,33 +1,33 @@
|
|||||||
<script>
|
<script>
|
||||||
import TodoHeader from './components/TodoHeader.vue'
|
import TodoHeader from "./components/TodoHeader.vue";
|
||||||
import TodoList from './components/TodoList.vue'
|
import TodoList from "./components/TodoList.vue";
|
||||||
import TodoFooter from './components/TodoFooter.vue'
|
import TodoFooter from "./components/TodoFooter.vue";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
TodoHeader,
|
TodoHeader,
|
||||||
TodoList,
|
TodoList,
|
||||||
TodoFooter
|
TodoFooter,
|
||||||
},
|
},
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
// 从 localStorage 初始化
|
// 从 localStorage 初始化
|
||||||
todos: JSON.parse(localStorage.getItem("vue-todos") || "[]"),
|
todos: JSON.parse(localStorage.getItem("vue-todos") || "[]"),
|
||||||
tabType: 0 // 0全部 1未完成 2已完成
|
tabType: 0, // 0全部 1未完成 2已完成
|
||||||
}
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
// 筛选后的列表
|
// 筛选后的列表
|
||||||
todoList() {
|
todoList() {
|
||||||
if (this.tabType === 0) return this.todos
|
if (this.tabType === 0) return this.todos;
|
||||||
const type = this.tabType
|
const type = this.tabType;
|
||||||
return this.todos.filter(item => {
|
return this.todos.filter((item) => {
|
||||||
if (type === 1) return !item.completed
|
if (type === 1) return !item.completed;
|
||||||
return item.completed
|
return item.completed;
|
||||||
})
|
});
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
@@ -36,34 +36,38 @@ export default {
|
|||||||
this.todos.push({
|
this.todos.push({
|
||||||
id: Date.now(),
|
id: Date.now(),
|
||||||
txt: newTodo,
|
txt: newTodo,
|
||||||
completed: false
|
completed: false,
|
||||||
})
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// 删除待办
|
// 删除待办
|
||||||
delTodo(item) {
|
delTodo(item) {
|
||||||
this.todos = this.todos.filter(t => t.id !== item.id)
|
this.todos = this.todos.filter((t) => t.id !== item.id);
|
||||||
},
|
},
|
||||||
|
|
||||||
changeTabType(type) {
|
changeTabType(type) {
|
||||||
this.tabType = type
|
this.tabType = type;
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
// 深度监听 — 自动写入 localStorage
|
// 深度监听 — 自动写入 localStorage
|
||||||
watch: {
|
watch: {
|
||||||
todos: {
|
todos: {
|
||||||
handler(todos) {
|
handler(todos) {
|
||||||
localStorage.setItem("vue-todos", JSON.stringify(todos))
|
localStorage.setItem("vue-todos", JSON.stringify(todos));
|
||||||
},
|
},
|
||||||
deep: true
|
deep: true,
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
}
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<TodoHeader @addTodo="addTodo" />
|
<TodoHeader @addTodo="addTodo" />
|
||||||
<TodoList :todos="todoList" @delTodo="delTodo" />
|
<TodoList :todos="todoList" @delTodo="delTodo" />
|
||||||
<TodoFooter :count="todoList.length" :tabType="tabType" @changeTabType="changeTabType" />
|
<TodoFooter
|
||||||
|
:count="todoList.length"
|
||||||
|
:tabType="tabType"
|
||||||
|
@changeTabType="changeTabType"
|
||||||
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -16,10 +16,10 @@ export default {
|
|||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
tabClick(newType) {
|
tabClick(newType) {
|
||||||
this.$emit("changeTabType", newType)
|
this.$emit("changeTabType", newType);
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
}
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|||||||
@@ -3,7 +3,11 @@
|
|||||||
<h1>待办事项</h1>
|
<h1>待办事项</h1>
|
||||||
|
|
||||||
<div class="input-wrapper">
|
<div class="input-wrapper">
|
||||||
<input placeholder="请输入您的待办事项,按下回车后即可添加" v-model.trim="newTodo" @keyup.enter="addNewTodo" />
|
<input
|
||||||
|
placeholder="请输入您的待办事项,按下回车后即可添加"
|
||||||
|
v-model.trim="newTodo"
|
||||||
|
@keyup.enter="addNewTodo"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p v-show="isShowMsg" style="color: red">
|
<p v-show="isShowMsg" style="color: red">
|
||||||
@@ -55,34 +59,31 @@ p {
|
|||||||
</style>
|
</style>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
const WORD_COUNT_LIMIT = 50
|
const WORD_COUNT_LIMIT = 50;
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
newTodo: "",
|
newTodo: "",
|
||||||
countLimit: WORD_COUNT_LIMIT
|
countLimit: WORD_COUNT_LIMIT,
|
||||||
}
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
isShowMsg() {
|
isShowMsg() {
|
||||||
return this.newTodo.length > WORD_COUNT_LIMIT
|
return this.newTodo.length > WORD_COUNT_LIMIT;
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
addNewTodo() {
|
addNewTodo() {
|
||||||
if (
|
if (this.newTodo.length === 0 || this.newTodo.length > WORD_COUNT_LIMIT) {
|
||||||
this.newTodo.length === 0 ||
|
return;
|
||||||
this.newTodo.length > WORD_COUNT_LIMIT
|
|
||||||
) {
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.$emit("addTodo", this.newTodo)
|
this.$emit("addTodo", this.newTodo);
|
||||||
this.newTodo = ""
|
this.newTodo = "";
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
}
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -99,8 +99,9 @@ export default {
|
|||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
delTodo(item) {
|
delTodo(item) {
|
||||||
this.$emit("delTodo", item)
|
this.$emit("delTodo", item);
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
}
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { createApp } from 'vue'
|
import { createApp } from "vue";
|
||||||
import App from './App.vue'
|
import App from "./App.vue";
|
||||||
import './assets/global.css'
|
import "./assets/global.css";
|
||||||
|
|
||||||
createApp(App).mount('#app')
|
createApp(App).mount("#app");
|
||||||
|
|||||||
@@ -81,4 +81,4 @@ button:focus-visible {
|
|||||||
button {
|
button {
|
||||||
background-color: #f9f9f9;
|
background-color: #f9f9f9;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { defineConfig } from 'vite'
|
import { defineConfig } from "vite";
|
||||||
import vue from '@vitejs/plugin-vue'
|
import vue from "@vitejs/plugin-vue";
|
||||||
|
|
||||||
// https://vite.dev/config/
|
// https://vite.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [vue()],
|
plugins: [vue()],
|
||||||
})
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user