-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathc27.html
172 lines (167 loc) · 5.39 KB
/
c27.html
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<script src="vue.js"></script>
<style>
*{
margin: 0;
padding: 0;
}
#app{
width: 800px;
/*margin: 0px auto 0 auto;*/
margin: 50px auto 0 auto;
/*background-color: aquamarine;*/
}
table{
width: 100%;
background-color: #000;
}
table tr{
background-color: #fff;
}
form{
width: 100%;
display: flex;
justify-content: space-between;
}
input{
text-align: center;
}
.v-enter{
opacity: 0;
}
.v-enter-to{
opacity: 1;
}
.v-enter-active{
transition: all .6s ease-in-out;
}
.v-leave{
opacity: 1;
}
.v-leave-to{
opacity: 0;
}
.v-leave-active{
transition: all .5s ease-in-out;
}
</style>
</head>
<body>
<div id="app">
<transition>
<form v-show="isShow">
<input type="text" placeholder="请输入序号" v-model="person.id">
<input type="text" placeholder="请输入姓名" v-model="person.name">
<input type="text" placeholder="请输入分数" v-model="person.score">
<input type="submit" value="新增" @click.prevent="add">
<input type="submit" value="查询" @click.prevent="query">
</form>
</transition>
<table>
<tr>
<th>序号</th>
<th>姓名</th>
<th>分数</th>
<th>时间</th>
<th>操作</th>
</tr>
<tr v-for="(person, index) in persons">
<!--<td><input type="text" :value="person.id" :disabled="isDisabled"></td>
<td><input type="text" :value="person.name" :disabled="isDisabled"></td>
<td><input type="text" :value="person.score" :disabled="isDisabled"></td>
<td><input type="text" :value="person.date | formatDate" :disabled="isDisabled"></td>-->
<td><input type="text" v-model="person.id" :disabled="isDisabled"></td>
<td><input type="text" v-model="person.name" :disabled="isDisabled"></td>
<td><input type="text" v-model="person.score" :disabled="isDisabled"></td>
<td><input type="text" :value="person.date | formatDate" disabled></td>
<td>
<a href="#" @click.prevent="edit">编辑</a>
<a href="#" @click.orevent="del(index)">删除</a>
<a href="#" @click.prevent="toggle">更多</a>
</td>
</tr>
</table>
</div>
<script>
Vue.filter("formatDate",(value) => {
let date = new Date(value);
let year = date.getFullYear();
let month = date.getMonth() + 1 +"";
let day = date.getDate() +"";
let hours = date.getHours() +"";
let minutes = date.getMinutes() +"";
let seconds = date.getSeconds() +"";
return `${year}-${month.padStart(2, "0")}-${day.padStart(2, "0")} ${hours.padStart(2, "0")}:${minutes.padStart(2, "0")}:${seconds.padStart(2, "0")}`;//padStart 判断长度条件 前一位参数为指定长度,若不满足则添加第二位自定义参数
});
let app = new Vue({
el: "#app",
data: { //这里是MVVM中的Model
isDisabled:true,
isShow:false,
persons:[{
id:1,
name:"zs",
score:"77",
date:Date.now()
},
{
id:2,
name:"ls",
score:"87",
date:Date.now()
},
{
id:3,
name:"es",
score:"69",
date:Date.now()
}],
person:{
id:"",
name:"",
score:"",
// date: Date.now()
}
},
methods: { // 专门用于存储监听事件的回调函数
edit() {
this.isDisabled = !this.isDisabled
},
toggle(){
this.isShow = !this.isShow
},
del(index){
// console.log(index);
this.persons.splice(index,1);
},
add(){
this.person.date = Date.now();
this.persons.push(this.person);
this.person = { //输入完一条数据后清空输入框
id:"",
name:"",
score:""
};
},
query(){
let newPersons = this.persons.filter((person) => {
// console.log(person.score === this.person.score);
// console.log(person.score);
console.log(person);
console.log(this.person.score);
if(person.score === this.person.score){
return true;
}
});
// console.log(newPersons);
this.persons = newPersons;
}
},
})
</script>
</body>
</html>