-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
264 lines (239 loc) · 5.25 KB
/
index.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>form</title>
<script type="text/javascript" src="js/vue.min.js"></script>
<style type="text/css">
#table table {
width: 100%;
font-size: 14px;
border: 1px solid #eee
}
#table {
padding: 0 10px;
}
table thead th {
background: #f5f5f5;
padding: 10px;
text-align: left;
}
table tbody td {
padding: 10px;
text-align: left;
border-bottom: 1px solid #eee;
border-right: 1px solid #eee;
}
table tbody td span {
margin: 0 10px;
cursor: pointer;
}
.delete {
color: red;
}
.edit {
color: #008cd5;
}
.add {
border: 1px solid #eee;
margin: 10px 0;
padding: 15px;
}
input {
border: 1px solid #ccc;
padding: 5px;
border-radius: 3px;
margin-right: 15px;
}
button {
background: #008cd5;
border: 0;
padding: 4px 15px;
border-radius: 3px;
color: #fff;
}
#mask {
background: rgba(0, 0, 0, .5);
width: 100%;
height: 100%;
position: fixed;
z-index: 4;
top: 0;
left: 0;
}
.mask {
width: 300px;
height: 250px;
background: rgba(255, 255, 255, 1);
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
margin: auto;
z-index: 47;
border-radius: 5px;
}
.title {
padding: 10px;
border-bottom: 1px solid #eee;
}
.title span {
float: right;
cursor: pointer;
}
.content {
padding: 10px;
}
.content input {
width: 270px;
margin-bottom: 15px;
}
</style>
</head>
<body>
<div id="table">
<div class="add">
<input type="text" v-model="addDetail.title" name="title" value="" placeholder="标题" />
<input type="text" v-model="addDetail.user" name="user" value="" placeholder="发布人" />
<input type="date" v-model="addDetail.dates" name="date" value="" placeholder="发布时间" />
<button @click="adddetail">新增</button>
</div>
<table cellpadding="0" cellspacing="0">
<thead>
<tr>
<th>序号</th>
<th>标题</th>
<th>发布人</th>
<th>发布时间</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr v-for="(item,index) in newsList">
<td width="5%">{{index+1}}</td>
<td>{{item.title}}</td>
<td width="10%">{{item.user}}</td>
<td width="15%">{{item.dates}}</td>
<td width="10%"><span @click="deletelist(item.id,index)" class="delete">删除</span><span class="edit" @click="edit(item)">编辑</span></td>
</tr>
</tbody>
</table>
<div id="mask" v-if="editlist">
<div class="mask">
<div class="title">
编辑
<span @click="editlist=false">
X
</span>
</div>
<div class="content">
<input type="text" v-model="editDetail.title" name="title" value="" placeholder="标题" />
<input type="text" v-model="editDetail.user" name="user" value="" placeholder="发布人" />
<input type="date" v-model="editDetail.dates" name="date" value="" placeholder="发布时间" />
<button @click="update">更新</button>
<button @click="editlist=false">取消</button>
</div>
</div>
</div>
</div>
<script>
var app = new Vue({
el: '#table',
data: {
addDetail: {},
editlist: false,
editDetail: {},
newsList: [{
title: '在移动设备开发',
user: '张若昀',
dates: '2018-02-09',
id: "45211546"
}, {
title: '图形及特效特性',
user: '张若昀',
dates: '2018-02-09',
id: "61341341"
}, {
title: '设备兼容特性',
user: '张若昀',
dates: '2018-02-09',
id: "62451431"
}, {
title: 'W3C将致力于开发用于实时通信',
user: '张若昀',
dates: '2018-02-09',
id: "62345213"
}, {
title: '全新的表单输入对象',
user: '张若昀',
dates: '2018-02-09',
id: "23322445"
}],
editid:''
},
mounted() {
},
methods: {
//新增
adddetail() {
//这里的思路应该是把this.addDetail传给服务端,然后加载列表this.newsList
//this.newsList.push(this.addDetail)
this.newsList.push({
title: this.addDetail.title,
user: this.addDetail.user,
dates: this.addDetail.dates,
})
//axios.post('url',this.addDetail).then((res) =>{
//若返回正确结果,清空新增输入框的数据
//this.addDetail.title = ""
//this.addDetail.user = ""
//this.addDetail.dates = ""
//})
},
//删除
deletelist(id, i) {
this.newsList.splice(i, 1);
//这边可以传id给服务端进行删除 ID = id
//axios.get('url',{ID:id}).then((res) =>{
// 加载列表
//})
},
//编辑
edit(item) {
this.editDetail = {
title: item.title,
user: item.user,
dates: item.dates,
id: item.id
}
this.editlist = true
this.editid = item.id
},
//确认更新
update() {
//编辑的话,也是传id去服务端
//axios.get('url',{ID:id}).then((res) =>{
// 加载列表
//})
let _this= this
for(let i = 0; i < _this.newsList.length; i++) {
if(_this.newsList[i].id ==this.editid) {
_this.newsList[i] = {
title: _this.editDetail.title,
user: _this.editDetail.user,
dates: _this.editDetail.dates,
id: this.editid
}
this.editlist = false
}
}
}
}
})
</script>
<div style="text-align:center;margin:50px 0; font:normal 14px/24px 'MicroSoft YaHei';">
</div>
</body>
</html>