<template>
<div id="app">
<div class="father">
<div class="one">
<a>ToDoList</a>
<input
placeholder="添加ToDo"
type="text"
class="input"
@keydown.enter="onsubmit"
v-model="inputvalue"
/>
</div>
<p v-show="show">请填写此字段</p>
</div>
<div class="content">
<div class="diyihang">
<span>正在进行</span>
<span class="numberOne">{{ dev.length }}</span>
</div>
<li v-for="item in dev" class="myValue" :key="item.id">
<input type="checkbox" class="btn" v-model="item.check" />
<p class="itemP">{{ item.value }}</p>
<a class="devA" ref="dev" @click="btnClickDelete(item.id)">删除</a>
</li>
</div>
<div class="dierhang">
<span>已经完成</span>
<span class="numberTwo">{{ achieve.length }}</span>
</div>
<div class="achieveAll">
<ul>
<li v-for="item in achieve" class="achieve" :key="item.id">
<input type="checkbox" class="achieveInput" v-model="item.check" />
<p class="achieveP">
{{ item.value }}
</p>
<a class="achieveA" ref="achieve" @click="btnClickDelete(item.id)">
删除
</a>
</li>
</ul>
</div>
<footer class="footer">
Copyright © 1024
<a @click="clear">clear</a>
</footer>
</div>
</template>
<script>
export default {
name: "App",
components: {},
data() {
return {
message: "此输入框不能为空",
inputvalue: "",
show: false,
myvalue: [],
uid: 0
};
},
methods: {
onsubmit() {
// 在input框中输入的数,如果为空,就让v-show为真
if (this.inputvalue.length === 0) {
this.show = true;
setTimeout(() => {
this.show = false;
}, 2000);
}
// 如果不为空,则将输入的数据push进一个空数组,并且将数据添加id和check属性,把对象加入空数组.
else {
this.show = false;
this.myvalue.push({
value: this.inputvalue,
check: false,
id: this.uid++
});
this.inputvalue = "";
}
},
// 点击删除按钮
btnClickDelete(id) {
// 如果点击的唯一id跟数组中对象遍历地id相同就返回那个数的下标,
let index = this.myvalue.findIndex(item => item.id === id);
// 根据下标删除那个数.
this.myvalue.splice(index, 1);
},
clear() {
// 点击清除按钮,让数据源为空,这里的是数组.
this.myvalue = [];
}
},
computed: {
dev() {
// 将数据源内部某个对象的check为false的对象返回给dev.
return this.myvalue.filter(item => !item.check);
},
achieve() {
// 将数据源内部某个对象的check为true的对象返回给achieve.
return this.myvalue.filter(item => item.check);
}
}
};
</script>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background-color: antiquewhite;
width: 100vw;
height: 100vh;
}
.father {
height: 50px;
width: 100%;
background-color: black;
display: flex;
justify-content: center;
align-items: center;
}
.one {
width: 600px;
height: 50px;
color: white;
line-height: 50px;
position: relative;
}
.one > a {
font-size: 25px;
width: 50px;
position: absolute;
}
.one > input {
width: 400px;
margin-left: 200px;
border-radius: 5px;
position: absolute;
line-height: 25px;
margin-top: 10px;
padding-left: 15px;
}
p {
display: block;
height: 30px;
width: 150px;
background-color: white;
line-height: 30px;
text-align: center;
margin: 0 auto;
position: fixed;
margin-left: 920px;
border-radius: 5px;
}
.content {
margin-top: 30px;
}
.diyihang {
width: 600px;
height: 60px;
margin: 0 auto;
position: relative;
}
.myValue {
width: 600px;
height: 40px;
background-color: white;
margin: 8px auto;
list-style: none;
position: relative;
line-height: 38px;
}
.btn {
width: 30px;
height: 30px;
border: 1px solid black;
border-radius: 3px;
margin-left: 10px;
font-size: 10px;
line-height: 30px;
text-align: center;
margin-top: 5px;
}
.itemP {
position: absolute;
height: 30px;
width: 200px;
line-height: 30px;
display: inline;
right: 250px;
top: 5px;
}
.devA {
width: 30px;
height: 30px;
border-radius: 3px;
position: absolute;
right: 20px;
border: 1px solid black;
line-height: 30px;
font-size: 10px;
text-align: center;
margin-top: 5px;
}
.diyihang > span {
font-size: 25px;
line-height: 60px;
position: absolute;
}
.diyihang > .numberOne {
position: absolute;
width: 25px;
height: 25px;
background-color: darkcyan;
text-align: center;
line-height: 25px;
border-radius: 50%;
margin-left: 550px;
margin-top: 15px;
font-size: 15px;
}
.dierhang {
width: 600px;
height: 60px;
margin: 0 auto;
position: relative;
}
.dierhang > span {
font-size: 25px;
line-height: 60px;
position: absolute;
}
.dierhang > .numberTwo {
width: 25px;
height: 25px;
background-color: darkcyan;
text-align: center;
line-height: 25px;
position: absolute;
border-radius: 50%;
margin-left: 550px;
margin-top: 15px;
font-size: 15px;
}
.achieve {
width: 600px;
height: 40px;
background-color: white;
margin: 8px auto;
list-style: none;
position: relative;
line-height: 38px;
}
.achieveInput {
width: 30px;
height: 30px;
position: absolute;
margin-top: 5px;
border-radius: 3px;
margin-left: 10px;
}
.achieveP {
display: inline;
position: absolute;
height: 30px;
width: 200px;
font-size: 15px;
line-height: 30px;
display: inline;
right: 250px;
top: 5px;
}
.achieveA {
position: absolute;
right: 20px;
border: 1px solid black;
border-radius: 3px;
height: 30px;
width: 30px;
font-size: 10px;
line-height: 30px;
text-align: center;
margin-top: 5px;
}
.footer {
text-align: center;
opacity: 0.6;
font-family: sans-serif;
width: 600px;
margin: 0 auto;
position: absolute;
left: 50%;
transform: translateX(-50%);
}
.footer > a {
opacity: 0.6;
}
</style>