-
Notifications
You must be signed in to change notification settings - Fork 841
/
App.vue
161 lines (150 loc) · 3.55 KB
/
App.vue
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
<script setup>
import { ref, shallowRef } from 'vue'
import { buildData } from './data'
const selected = ref()
const rows = shallowRef([])
function setRows(update = rows.value.slice()) {
rows.value = update
}
function add() {
rows.value = rows.value.concat(buildData(1000))
}
function remove(id) {
rows.value.splice(
rows.value.findIndex((d) => d.id === id),
1
)
setRows()
}
function select(id) {
selected.value = id
}
function run() {
setRows(buildData())
selected.value = undefined
}
function update() {
const _rows = rows.value
for (let i = 0; i < _rows.length; i += 10) {
_rows[i].label += ' !!!'
}
setRows()
}
function runLots() {
setRows(buildData(10000))
selected.value = undefined
}
function clear() {
setRows([])
selected.value = undefined
}
function swapRows() {
const _rows = rows.value
if (_rows.length > 998) {
const d1 = _rows[1]
const d998 = _rows[998]
_rows[1] = d998
_rows[998] = d1
setRows()
}
}
</script>
<template>
<div class="jumbotron">
<div class="row">
<div class="col-md-6">
<h1>Vue.js 3 (keyed)</h1>
</div>
<div class="col-md-6">
<div class="row">
<div class="col-sm-6 smallpad">
<button
type="button"
class="btn btn-primary btn-block"
id="run"
@click="run"
>
Create 1,000 rows
</button>
</div>
<div class="col-sm-6 smallpad">
<button
type="button"
class="btn btn-primary btn-block"
id="runlots"
@click="runLots"
>
Create 10,000 rows
</button>
</div>
<div class="col-sm-6 smallpad">
<button
type="button"
class="btn btn-primary btn-block"
id="add"
@click="add"
>
Append 1,000 rows
</button>
</div>
<div class="col-sm-6 smallpad">
<button
type="button"
class="btn btn-primary btn-block"
id="update"
@click="update"
>
Update every 10th row
</button>
</div>
<div class="col-sm-6 smallpad">
<button
type="button"
class="btn btn-primary btn-block"
id="clear"
@click="clear"
>
Clear
</button>
</div>
<div class="col-sm-6 smallpad">
<button
type="button"
class="btn btn-primary btn-block"
id="swaprows"
@click="swapRows"
>
Swap Rows
</button>
</div>
</div>
</div>
</div>
</div>
<table class="table table-hover table-striped test-data">
<tbody>
<tr
v-for="{ id, label } of rows"
:key="id"
:class="{ danger: id === selected }"
:data-label="label"
v-memo="[label, id === selected]"
>
<td class="col-md-1">{{ id }}</td>
<td class="col-md-4">
<a @click="select(id)">{{ label }}</a>
</td>
<td class="col-md-1">
<a @click="remove(id)">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</a>
</td>
<td class="col-md-6"></td>
</tr>
</tbody>
</table>
<span
class="preloadicon glyphicon glyphicon-remove"
aria-hidden="true"
></span>
</template>