20
20
:items =" dataList"
21
21
:item-size =" itemSize"
22
22
:buffer =" 50"
23
- v-slot =" { active, item }"
24
23
>
25
- <ElTreeVirtualNode
26
- v-if =" active"
27
- :style =" `height: ${itemSize}px;`"
28
- :node =" item"
29
- :item-size =" itemSize"
30
- :render-content =" renderContent"
31
- :show-checkbox =" showCheckbox"
32
- :render-after-expand =" renderAfterExpand"
33
- @node-expand =" handleNodeExpand"
34
- />
24
+ <template slot-scope="{ active, item }">
25
+ <ElTreeVirtualNode
26
+ v-if =" active"
27
+ :style =" `height: ${itemSize}px;`"
28
+ :node =" item"
29
+ :item-size =" itemSize"
30
+ :render-content =" renderContent"
31
+ :show-checkbox =" showCheckbox"
32
+ :render-after-expand =" renderAfterExpand"
33
+ @node-expand =" handleNodeExpand"
34
+ />
35
+ </template >
35
36
</RecycleScroller >
36
37
<template v-else-if =" ! height " >
37
38
<el-tree-node
@@ -210,12 +211,7 @@ export default {
210
211
},
211
212
212
213
dataList () {
213
- const a = this .smoothTree (this .root .childNodes );
214
- const b = [];
215
- a .forEach ((e ) => {
216
- b .push (e .key );
217
- });
218
- return a;
214
+ return this .smoothTree (this .root .childNodes );
219
215
},
220
216
},
221
217
@@ -267,6 +263,25 @@ export default {
267
263
this .store .filter (value);
268
264
},
269
265
266
+ scrollToItem (key ) {
267
+ if (this .height && ! this .isEmpty ) {
268
+ const virtualInstance = this .$children .find (
269
+ (c ) => c .$options .name === " RecycleScroller"
270
+ );
271
+ // Automatically scroll the target item to the top
272
+ const index = virtualInstance .items .findIndex ((e ) => {
273
+ return e .key === key;
274
+ });
275
+ this .$nextTick (() => {
276
+ virtualInstance .scrollToItem (index);
277
+ });
278
+ } else {
279
+ throw new Error (
280
+ " scrollToItem can only be used when using virtual scrolling"
281
+ );
282
+ }
283
+ },
284
+
270
285
getNodeKey (node ) {
271
286
return getNodeKey (this .nodeKey , node .data );
272
287
},
@@ -650,4 +665,4 @@ export default {
650
665
this .checkboxItems = this .$el .querySelectorAll (" input[type=checkbox]" );
651
666
},
652
667
};
653
- </script >
668
+ </script >
0 commit comments