2020 :items =" dataList"
2121 :item-size =" itemSize"
2222 :buffer =" 50"
23- v-slot =" { active, item }"
2423 >
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 >
3536 </RecycleScroller >
3637 <template v-else-if =" ! height " >
3738 <el-tree-node
@@ -210,12 +211,7 @@ export default {
210211 },
211212
212213 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 );
219215 },
220216 },
221217
@@ -267,6 +263,25 @@ export default {
267263 this .store .filter (value);
268264 },
269265
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+
270285 getNodeKey (node ) {
271286 return getNodeKey (this .nodeKey , node .data );
272287 },
@@ -650,4 +665,4 @@ export default {
650665 this .checkboxItems = this .$el .querySelectorAll (" input[type=checkbox]" );
651666 },
652667};
653- </script >
668+ </script >
0 commit comments