-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.vue
More file actions
78 lines (73 loc) · 1.81 KB
/
App.vue
File metadata and controls
78 lines (73 loc) · 1.81 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
<template>
<div id="app">
<h3>{{ message }}</h3>
<div>
<div>
<div v-for="item of oldArray" @click="addItem(item, $event)">{{item.name}}</div>
</div>
<div>
<ul>
<child-li :item="item" v-for="item of tempArray" :key="item.name"/>
</ul>
</div>
</div>
</div>
</template>
<script>
import childLi from './components/childLi'
export default {
name: 'App',
components: {
childLi
},
data() {
return {
message: '这就是一个 表格',
oldArray: [],
tempArray: []
}
},
created() {
this.oldArray = [
{
name: '旧数据111',
time: new Date(),
isChecked: false,
},
{
name: '旧数据222',
time: new Date(),
isChecked: false,
}
]
},
methods: {
addItem(item, event) {
// 处理颜色、增加数据
if (event.toElement.getAttribute("style") !== "background-color: red") {
item.isChecked = true;
event.toElement.setAttribute("style", "background-color: red")
this.tempArray.push(item)
} else {
// 删除数据
event.toElement.removeAttribute("style")
console.log('----------this.tempArray.indexOf(item)----------', this.tempArray.indexOf(item))
if (this.tempArray.indexOf(item) > -1) {
this.tempArray.splice(this.tempArray.indexOf(item), 1)
}
console.log('---------after-remove----------', this.tempArray)
}
}
}
}
</script>
<style>
#app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2C3E50;
margin-top: 60px;
}
</style>