parent
28afd9565c
commit
fc16f91859
@ -0,0 +1,29 @@
|
||||
# todo-list
|
||||
|
||||
This template should help get you started developing with Vue 3 in Vite.
|
||||
|
||||
## Recommended IDE Setup
|
||||
|
||||
[VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur).
|
||||
|
||||
## Customize configuration
|
||||
|
||||
See [Vite Configuration Reference](https://vite.dev/config/).
|
||||
|
||||
## Project Setup
|
||||
|
||||
```sh
|
||||
npm install
|
||||
```
|
||||
|
||||
### Compile and Hot-Reload for Development
|
||||
|
||||
```sh
|
||||
npm run dev
|
||||
```
|
||||
|
||||
### Compile and Minify for Production
|
||||
|
||||
```sh
|
||||
npm run build
|
||||
```
|
@ -0,0 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<link rel="icon" href="/favicon.ico">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Vite App</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.js"></script>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,8 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"paths": {
|
||||
"@/*": ["./src/*"]
|
||||
}
|
||||
},
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "todo-list",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"lodash.uniqueid": "^4.0.1",
|
||||
"vue": "^3.5.13"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vitejs/plugin-vue": "^5.2.1",
|
||||
"vite": "^6.1.0",
|
||||
"vite-plugin-vue-devtools": "^7.7.2"
|
||||
}
|
||||
}
|
After Width: | Height: | Size: 4.2 KiB |
@ -0,0 +1,180 @@
|
||||
<script>
|
||||
import ToDoItem from './components/ToDoItem.vue';
|
||||
import uniqueId from 'lodash.uniqueId';
|
||||
import ToDoForm from './components/ToDoForm.vue';
|
||||
|
||||
export default {
|
||||
name: 'app',
|
||||
components: {
|
||||
ToDoItem,
|
||||
ToDoForm,
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
ToDoItems: [
|
||||
{ id: uniqueId("todo-"), label: "Learn Vue", done: false },
|
||||
{
|
||||
id: uniqueId("todo-"),
|
||||
label: "Create a Vue project with the CLI",
|
||||
done: true,
|
||||
},
|
||||
{ id: uniqueId("todo-"), label: "Have fun", done: true },
|
||||
{ id: uniqueId("todo-"), label: "Create a to-do list", done: false },
|
||||
],
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
addToDo(toDoLabel){
|
||||
this.ToDoItems.push({id:uniqueId("todo-"),label:toDoLabel,done:false}) //父子组件通信
|
||||
},
|
||||
updateDoneStatus(toDoId) {
|
||||
const toDoToUpdate = this.ToDoItems.find((item) => item.id === toDoId);
|
||||
toDoToUpdate.done =!toDoToUpdate.done;
|
||||
},
|
||||
deleteToDo(toDoId) {
|
||||
const itemIndex = this.ToDoItems.findIndex((item) => item.id === toDoId);
|
||||
this.ToDoItems.splice(itemIndex, 1);
|
||||
},
|
||||
editToDo(toDoId, newLabel) {
|
||||
const toDoToEdit = this.ToDoItems.find((item) => item.id === toDoId);
|
||||
toDoToEdit.label = newLabel;
|
||||
}
|
||||
|
||||
},
|
||||
computed: {
|
||||
listSummary() {
|
||||
const numberFinishedItems = this.ToDoItems.filter((item) => item.done).length;
|
||||
return `${numberFinishedItems} out of ${this.ToDoItems.length} items completed`
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div id="app">
|
||||
<h1>To-Do List</h1>
|
||||
<to-do-form @todo-added="addToDo"></to-do-form> <!-- add event listener to form -->
|
||||
<h2 id="list-summary">{{ listSummary }}</h2>
|
||||
<ul aria-labelledby="list-summary" class="stack-large">
|
||||
<li v-for="item in ToDoItems" :key="item.id">
|
||||
<to-do-item :label="item.label" :done="item.done" :id="item.id" @checkbox-changed="updateDoneStatus(item.id)" @item-deleted="deleteToDo(item.id)" @item-edited="editToDo(item.id,$event)"></to-do-item>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style >
|
||||
/* 全局样式 */
|
||||
.btn {
|
||||
padding: 0.8rem 1rem 0.7rem;
|
||||
border: 0.2rem solid #4d4d4d;
|
||||
cursor: pointer;
|
||||
text-transform: capitalize;
|
||||
border-radius: 5px; /* 圆角 */
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); /* 阴影效果 */
|
||||
}
|
||||
.btn__danger {
|
||||
color: #fff;
|
||||
background-color: #ca3c3c;
|
||||
border-color: #bd2130;
|
||||
}
|
||||
.btn__filter {
|
||||
border-color: lightgrey;
|
||||
}
|
||||
.btn__danger:focus {
|
||||
outline-color: #c82333;
|
||||
}
|
||||
.btn__primary {
|
||||
color: #fff;
|
||||
background-color: #000;
|
||||
}
|
||||
.btn-group {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
}
|
||||
.btn-group > * {
|
||||
flex: 1 1 auto;
|
||||
}
|
||||
.btn-group > * + * {
|
||||
margin-left: 0.8rem;
|
||||
}
|
||||
.label-wrapper {
|
||||
margin: 0;
|
||||
flex: 0 0 100%;
|
||||
text-align: center;
|
||||
}
|
||||
[class*="__lg"] {
|
||||
display: inline-block;
|
||||
width: 100%;
|
||||
font-size: 1.9rem;
|
||||
}
|
||||
[class*="__lg"]:not(:last-child) {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
@media screen and (min-width: 620px) {
|
||||
[class*="__lg"] {
|
||||
font-size: 2.4rem;
|
||||
}
|
||||
}
|
||||
.visually-hidden {
|
||||
position: absolute;
|
||||
height: 1px;
|
||||
width: 1px;
|
||||
overflow: hidden;
|
||||
clip: rect(1px 1px 1px 1px);
|
||||
clip: rect(1px, 1px, 1px, 1px);
|
||||
clip-path: rect(1px, 1px, 1px, 1px);
|
||||
white-space: nowrap;
|
||||
}
|
||||
[class*="stack"] > * {
|
||||
margin-top: 0;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
.stack-small > * + * {
|
||||
margin-top: 1.25rem;
|
||||
}
|
||||
.stack-large > * + * {
|
||||
margin-top: 2.5rem;
|
||||
}
|
||||
@media screen and (min-width: 550px) {
|
||||
.stack-small > * + * {
|
||||
margin-top: 1.4rem;
|
||||
}
|
||||
.stack-large > * + * {
|
||||
margin-top: 2.8rem;
|
||||
}
|
||||
}
|
||||
/* 全局样式结束 */
|
||||
#app {
|
||||
background: #fff;
|
||||
margin: 2rem 0 4rem 0;
|
||||
padding: 1rem;
|
||||
padding-top: 0;
|
||||
position: relative;
|
||||
box-shadow:
|
||||
0 2px 4px 0 rgba(0, 0, 0, 0.2),
|
||||
0 2.5rem 5rem 0 rgba(0, 0, 0, 0.1);
|
||||
border-radius: 10px; /* 圆角 */
|
||||
}
|
||||
@media screen and (min-width: 550px) {
|
||||
#app {
|
||||
padding: 4rem;
|
||||
}
|
||||
}
|
||||
#app > * {
|
||||
max-width: 50rem;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
#app > form {
|
||||
max-width: 100%;
|
||||
}
|
||||
#app h1 {
|
||||
display: block;
|
||||
min-width: 100%;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
margin: 0;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
</style>
|
@ -0,0 +1,77 @@
|
||||
/*reset.css*/
|
||||
/* RESETS */
|
||||
*,
|
||||
*::before,
|
||||
*::after {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
*:focus {
|
||||
outline: 3px dashed #228bec;
|
||||
}
|
||||
html {
|
||||
font: 62.5% / 1.15 sans-serif;
|
||||
}
|
||||
h1,
|
||||
h2 {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
ul {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
}
|
||||
button {
|
||||
border: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
width: auto;
|
||||
overflow: visible;
|
||||
background: transparent;
|
||||
color: inherit;
|
||||
font: inherit;
|
||||
line-height: normal;
|
||||
-webkit-font-smoothing: inherit;
|
||||
-moz-osx-font-smoothing: inherit;
|
||||
appearance: none;
|
||||
}
|
||||
button::-moz-focus-inner {
|
||||
border: 0;
|
||||
}
|
||||
button,
|
||||
input,
|
||||
optgroup,
|
||||
select,
|
||||
textarea {
|
||||
font-family: inherit;
|
||||
font-size: 100%;
|
||||
line-height: 1.15;
|
||||
margin: 0;
|
||||
}
|
||||
button,
|
||||
input {
|
||||
/* 1 */
|
||||
overflow: visible;
|
||||
}
|
||||
input[type="text"] {
|
||||
border-radius: 0;
|
||||
}
|
||||
body {
|
||||
width: 100%;
|
||||
max-width: 68rem;
|
||||
margin: 0 auto;
|
||||
font:
|
||||
1.6rem/1.25 "Helvetica Neue",
|
||||
Helvetica,
|
||||
Arial,
|
||||
sans-serif;
|
||||
background-color: #f5f5f5;
|
||||
color: #4d4d4d;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
@media screen and (min-width: 620px) {
|
||||
body {
|
||||
font-size: 1.9rem;
|
||||
line-height: 1.31579;
|
||||
}
|
||||
}
|
||||
/*END RESETS*/
|
@ -0,0 +1,43 @@
|
||||
<template>
|
||||
<form @submit.prevent="onSubmit"> <!-- prevent default behavior of form submission(to server) -->
|
||||
<h2 class="label-wrapper">
|
||||
<label for="new-to-do-input">New To-Do:</label>
|
||||
</h2>
|
||||
<input type="text" id="new-todo-input" name="new-todo" autocomplete="off" v-model.trim.lazy="label" class="input__lg"/> <!-- v-model绑定到data中的label变量,保持同步-->
|
||||
<button type="submit" class="btn btn__primary btn__lg">Add</button>
|
||||
</form>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
methods: {
|
||||
onSubmit() {
|
||||
if(this.label === "") {
|
||||
alert("Please enter a to-do item");
|
||||
return;
|
||||
}
|
||||
this.$emit("todo-added", this.label); // 触发父组件的add-todo事件,并传入label作为参数},
|
||||
this.label = ""; // 清空输入框
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return{
|
||||
label:" ",
|
||||
};
|
||||
},
|
||||
|
||||
};
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.input__lg {
|
||||
border-radius: 5px; /* 圆角 */
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); /* 阴影效果 */
|
||||
}
|
||||
.btn {
|
||||
background-color: #007bff; /* 现代蓝色 */
|
||||
color: white;
|
||||
border-radius: 5px; /* 圆角 */
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); /* 阴影效果 */
|
||||
}
|
||||
</style>
|
@ -0,0 +1,101 @@
|
||||
<template>
|
||||
<form class="stack-small" @submit.prevent="onSubmit">
|
||||
<div>
|
||||
<label class="edit-label">Edit Name for "{{label}}"</label>
|
||||
<input
|
||||
:id="id"
|
||||
type="text"
|
||||
autocomplete="off"
|
||||
v-model.lazy.trim="newLabel" />
|
||||
</div>
|
||||
<div class="btn-group">
|
||||
|
||||
<button type="button" class="btn" @click="onCancel">
|
||||
Cancel
|
||||
<span class="visually-hidden">editing {{label}}</span>
|
||||
</button>
|
||||
|
||||
<button type="submit" class="btn btn__primary">
|
||||
Save
|
||||
<span class="visually-hidden">edit for {{label}}</span>
|
||||
</button>
|
||||
|
||||
</div>
|
||||
</form>
|
||||
</template>
|
||||
|
||||
|
||||
<script>
|
||||
export default {
|
||||
props: {
|
||||
label: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
id: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
newLabel: this.label,
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
onSubmit() {
|
||||
if (this.newLabel && this.newLabel !== this.label) {
|
||||
this.$emit("item-edited", this.newLabel);
|
||||
}
|
||||
},
|
||||
onCancel() {
|
||||
this.$emit("edit-cancelled");
|
||||
},
|
||||
deleteToDo(toDoId){
|
||||
const itemIndex = this.ToDoItems.findIndex(item => item.id === toDoId);
|
||||
this.ToDoItems.splice(itemIndex, 1);
|
||||
},
|
||||
editToDo(toDoId, newLabel){
|
||||
const toDoEdit = this.ToDoItems.find(item => item.id === toDoId);
|
||||
toDoEdit.label = newLabel;
|
||||
}
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
|
||||
<style scoped>
|
||||
.edit-label {
|
||||
font-family: Arial, sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
color: #333;
|
||||
display: block;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
input {
|
||||
display: inline-block;
|
||||
margin-top: 0.4rem;
|
||||
width: 100%;
|
||||
min-height: 4.4rem;
|
||||
padding: 0.4rem 0.8rem;
|
||||
border: 2px solid #565656;
|
||||
border-radius: 5px;
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
form {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
form > * {
|
||||
flex: 0 0 100%;
|
||||
}
|
||||
.btn {
|
||||
background-color: #007bff;
|
||||
color: white;
|
||||
border-radius: 5px;
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
</style>
|
||||
|
@ -0,0 +1,5 @@
|
||||
import { createApp } from 'vue'
|
||||
import App from './App.vue'
|
||||
import "./assets/style.css"
|
||||
|
||||
createApp(App).mount('#app')
|
@ -0,0 +1,18 @@
|
||||
import { fileURLToPath, URL } from 'node:url'
|
||||
|
||||
import { defineConfig } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
import vueDevTools from 'vite-plugin-vue-devtools'
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
vue(),
|
||||
vueDevTools(),
|
||||
],
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': fileURLToPath(new URL('./src', import.meta.url))
|
||||
},
|
||||
},
|
||||
})
|
Loading…
Reference in new issue