Skip to content

Commit

Permalink
fix #13 #17 #19 #22 #24
Browse files Browse the repository at this point in the history
  • Loading branch information
wchbrad committed Mar 27, 2023
1 parent e759431 commit 9833dde
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 20 deletions.
7 changes: 7 additions & 0 deletions dist/vue-easy-tree.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@wchbrad/vue-easy-tree",
"description": "A Vue.js project",
"version": "1.0.10",
"version": "1.0.11",
"author": "wchbrad <chao.wu.brad@foxmail.com>",
"license": "MIT",
"private": false,
Expand Down Expand Up @@ -32,7 +32,7 @@
],
"dependencies": {
"vue": "2.6.11",
"vue-virtual-scroller": "^1.0.10"
"vue-virtual-scroller": "~1.0.10"
},
"devDependencies": {
"@babel/core": "^7.19.3",
Expand Down
51 changes: 33 additions & 18 deletions src/components/ve-tree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,19 @@
:items="dataList"
:item-size="itemSize"
:buffer="50"
v-slot="{ active, item }"
>
<ElTreeVirtualNode
v-if="active"
:style="`height: ${itemSize}px;`"
:node="item"
:item-size="itemSize"
:render-content="renderContent"
:show-checkbox="showCheckbox"
:render-after-expand="renderAfterExpand"
@node-expand="handleNodeExpand"
/>
<template slot-scope="{ active, item }">
<ElTreeVirtualNode
v-if="active"
:style="`height: ${itemSize}px;`"
:node="item"
:item-size="itemSize"
:render-content="renderContent"
:show-checkbox="showCheckbox"
:render-after-expand="renderAfterExpand"
@node-expand="handleNodeExpand"
/>
</template>
</RecycleScroller>
<template v-else-if="!height">
<el-tree-node
Expand Down Expand Up @@ -210,12 +211,7 @@ export default {
},
dataList() {
const a = this.smoothTree(this.root.childNodes);
const b = [];
a.forEach((e) => {
b.push(e.key);
});
return a;
return this.smoothTree(this.root.childNodes);
},
},
Expand Down Expand Up @@ -267,6 +263,25 @@ export default {
this.store.filter(value);
},
scrollToItem(key) {
if (this.height && !this.isEmpty) {
const virtualInstance = this.$children.find(
(c) => c.$options.name === "RecycleScroller"
);
// Automatically scroll the target item to the top
const index = virtualInstance.items.findIndex((e) => {
return e.key === key;
});
this.$nextTick(() => {
virtualInstance.scrollToItem(index);
});
} else {
throw new Error(
"scrollToItem can only be used when using virtual scrolling"
);
}
},
getNodeKey(node) {
return getNodeKey(this.nodeKey, node.data);
},
Expand Down Expand Up @@ -650,4 +665,4 @@ export default {
this.checkboxItems = this.$el.querySelectorAll("input[type=checkbox]");
},
};
</script>
</script>

0 comments on commit 9833dde

Please sign in to comment.