Skip to content

Commit 9833dde

Browse files
committed
fix #13 #17 #19 #22 #24
1 parent e759431 commit 9833dde

File tree

3 files changed

+42
-20
lines changed

3 files changed

+42
-20
lines changed

dist/vue-easy-tree.js

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@wchbrad/vue-easy-tree",
33
"description": "A Vue.js project",
4-
"version": "1.0.10",
4+
"version": "1.0.11",
55
"author": "wchbrad <[email protected]>",
66
"license": "MIT",
77
"private": false,
@@ -32,7 +32,7 @@
3232
],
3333
"dependencies": {
3434
"vue": "2.6.11",
35-
"vue-virtual-scroller": "^1.0.10"
35+
"vue-virtual-scroller": "~1.0.10"
3636
},
3737
"devDependencies": {
3838
"@babel/core": "^7.19.3",

src/components/ve-tree.vue

+33-18
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,19 @@
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

Comments
 (0)