1
- import { defineComponent , ref , shallowRef } from "vue/vapor " ;
1
+ import { defineComponent , ref , shallowRef , triggerRef } from "vue" ;
2
2
import { buildData } from "./data" ;
3
3
export default defineComponent ( {
4
4
setup ( ) {
5
5
const selected = ref ( ) ;
6
6
const rows = shallowRef ( [ ] ) ;
7
7
8
- function setRows ( update = rows . value . slice ( ) ) {
9
- rows . value = update ;
10
- }
11
-
12
8
function add ( ) {
13
- rows . value = rows . value . concat ( buildData ( 1000 ) ) ;
9
+ rows . value . push ( ...buildData ( 1000 ) ) ;
10
+ triggerRef ( rows ) ;
14
11
}
15
12
16
13
function remove ( id ) {
17
14
rows . value . splice (
18
15
rows . value . findIndex ( ( d ) => d . id === id ) ,
19
16
1
20
17
) ;
21
- setRows ( ) ;
18
+ triggerRef ( rows ) ;
22
19
}
23
20
24
21
function select ( id ) {
25
22
selected . value = id ;
26
23
}
27
24
28
25
function run ( ) {
29
- setRows ( buildData ( ) ) ;
26
+ rows . value = buildData ( ) ;
30
27
selected . value = undefined ;
31
28
}
32
29
33
30
function update ( ) {
34
31
const _rows = rows . value ;
35
32
for ( let i = 0 ; i < _rows . length ; i += 10 ) {
36
- _rows [ i ] . label += " !!!" ;
33
+ _rows [ i ] . label . value += " !!!" ;
37
34
}
38
- setRows ( ) ;
39
35
}
40
36
41
37
function runLots ( ) {
42
- setRows ( buildData ( 10000 ) ) ;
38
+ rows . value = buildData ( 10000 ) ;
43
39
selected . value = undefined ;
44
40
}
45
41
46
42
function clear ( ) {
47
- setRows ( [ ] ) ;
43
+ rows . value = [ ] ;
48
44
selected . value = undefined ;
49
45
}
50
46
@@ -55,7 +51,7 @@ export default defineComponent({
55
51
const d998 = _rows [ 998 ] ;
56
52
_rows [ 1 ] = d998 ;
57
53
_rows [ 998 ] = d1 ;
58
- setRows ( ) ;
54
+ triggerRef ( rows ) ;
59
55
}
60
56
}
61
57
@@ -64,7 +60,7 @@ export default defineComponent({
64
60
< div class = "jumbotron" >
65
61
< div class = "row" >
66
62
< div class = "col-md-6" >
67
- < h1 > Vue.js JSX Vapor (keyed)</ h1 >
63
+ < h1 > Vue JSX Vapor (keyed)</ h1 >
68
64
</ div >
69
65
70
66
< div class = "col-md-6" >
@@ -110,22 +106,18 @@ export default defineComponent({
110
106
111
107
< table class = "table table-hover table-striped test-data" >
112
108
< tbody >
113
- { rows . value . map ( ( ctx ) => {
114
- return (
115
- < tr key = { ctx . id } class = { { danger : ctx . id === selected . value } } data-label = { ctx . label } >
116
- < td class = "col-md-1" > { ctx . id } </ td >
117
- < td class = "col-md-4" >
118
- < a onClick = { ( ) => select ( ctx . id ) } > { ctx . label } </ a >
119
- </ td >
120
- < td class = "col-md-1" >
121
- < a onClick = { ( ) => remove ( ctx . id ) } >
122
- < span class = "glyphicon glyphicon-remove" aria-hidden = "true" > </ span >
123
- </ a >
124
- </ td >
125
- < td class = "col-md-6" > </ td >
126
- </ tr >
127
- ) ;
128
- } ) }
109
+ < tr v-for = { ctx in rows . value } key = { ctx . id } class = { { danger : ctx . id === selected . value } } data-label = { ctx . label . value } >
110
+ < td class = "col-md-1" > { ctx . id } </ td >
111
+ < td class = "col-md-4" >
112
+ < a onClick = { ( ) => select ( ctx . id ) } > { ctx . label . value } </ a >
113
+ </ td >
114
+ < td class = "col-md-1" >
115
+ < a onClick = { ( ) => remove ( ctx . id ) } >
116
+ < span class = "glyphicon glyphicon-remove" aria-hidden = "true" > </ span >
117
+ </ a >
118
+ </ td >
119
+ < td class = "col-md-6" > </ td >
120
+ </ tr >
129
121
</ tbody >
130
122
</ table >
131
123
< span class = "preloadicon glyphicon glyphicon-remove" aria-hidden = "true" > </ span >
0 commit comments