-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.vue
More file actions
165 lines (158 loc) · 5.11 KB
/
Test.vue
File metadata and controls
165 lines (158 loc) · 5.11 KB
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
<template>
<div id="app">
<fieldset>
<legend>
Create New Person
</legend>
<div class="form-group">
<label>Name:</label>
<input type="text" v-model="newPerson.name"/>
</div>
<h1></h1>
<div class="form-group">
<label>Age:</label>
<input type="text" v-model="newPerson.age"/>
</div>
<h1></h1>
<div class="form-group">
<label>Sex:</label>
<select v-model="newPerson.sex">
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
</div>
<h1></h1>
<div class="form-group">
<label></label>
<button id="c-Button" @click="createPerson">Create</button>
<!-- <button id="c-Button" v-on:click="createPerson">Create</button> -->
</div>
<h1></h1>
</fieldset>
<!-- <table width=90% align=center border="1px" border-color=#42b983> -->
<table id="customers">
<thead>
<tr>
<th bgcolor=#42b983>Name</th>
<th bgcolor=#42b983>Age</th>
<th bgcolor=#42b983> Sex</th>
<th bgcolor=#42b983>Operation</th>
</tr>
</thead>
<tbody>
<tr v-for="(person,index) in people"
:key="person in people">
<td>
<input type="text" v-model="person.name" v-if="editlist===index">
<span v-else>{{person.name}}</span>
</td>
<td>
<input type="text" v-model="person.age" v-if="editlist===index">
<span v-else>{{person.age}}</span>
</td>
<td>
<input type="text" v-model="person.sex" v-if="editlist===index">
<span v-else>{{person.sex}}</span>
</td>
<td :class="'text-center'">
<button id="c-Button" @click="deletePerson(index)">Delete</button>
<button id="c-Button" @click="editPerson(index)">Edit</button>
<button id="c-Button" @click="save(index)">save</button>
<!-- <button id="c-Button" @click="submit">submit</button> -->
</td>
<!-- <td :class="'text-center'"><button id="c-Button" v-on:click="deletePerson($index)">Delete</button></td> -->
</tr>
</tbody>
</table>
</div>
</template>
<script>
export default {
name:'HelloWorld',
data(){
return{
editlist:'',
newPerson: {
name: '',
age: 0,
sex: 'Male'
},
people: [{
name: 'Jack',
age: 30,
sex: 'Male'
}, {
name: 'Bill',
age: 26,
sex: 'Male'
}, {
name: 'Tracy',
age: 22,
sex: 'Female'
}, {
name: 'Chris',
age: 36,
sex: 'Male'
}],
}
},
methods:{
createPerson: function(){
this.people.push(this.newPerson);
// 添加完newPerson对象后,重置newPerson对象
this.newPerson = {name: '', age: 0, sex: 'Male'}
},
deletePerson: function(index){
// 删一个数组元素
this.people.splice(index,1);
},
editPerson:function(index){
this.editlist=index;
},
save:function(index){
this.editlist=!index;
},
// submit:function () {
// this.editist='';
// console.log(JSON.stringify(this.people))
// }
}
}
</script>
<style>
#customers
{
font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
width:100%;
border-collapse:collapse;
}
#customers td, #customers th
{
font-size:1em;
border:1px solid #42b983;
padding:3px 7px 2px 7px;
}
#customers th
{
font-size:1.1em;
text-align:center;
padding-top:5px;
padding-bottom:4px;
background-color:#42b983;
color:#ffffff;
}
#customers tr.alt td
{
color:#000000;
background-color:#EAF2D3;
}
</style>
<style>
#c-Button{
background-color:#42b983;
border-color:#42b983;
border-radius: 4px;
}
</style>
<style>
</style>