Skip to content

Commit

Permalink
feat: add Tree LoadData demo
Browse files Browse the repository at this point in the history
  • Loading branch information
jinmao88 committed Jun 23, 2021
1 parent 8d22231 commit 9298b3c
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions src/views/demo/tree/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@
class="w-1/3"
/>
</div>
<div class="flex">
<BasicTree title="异步树" :treeData="tree" class="w-1/3" :load-data="onLoadData" />
</div>
</PageWrapper>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { defineComponent, ref } from 'vue';
import { BasicTree } from '/@/components/Tree/index';
import { treeData } from './data';
import { PageWrapper } from '/@/components/Page';
Expand All @@ -40,7 +43,34 @@
function handleCheck(checkedKeys, e) {
console.log('onChecked', checkedKeys, e);
}
return { treeData, handleCheck };
const tree = ref([
{
title: 'parent ',
key: '0-0',
},
]);
function onLoadData(treeNode) {
return new Promise((resolve: (value?: unknown) => void) => {
if (!treeNode.children) {
resolve();
return;
}
setTimeout(() => {
tree.value.forEach((v) => {
if (v.key === treeNode.eventKey) {
v.children = [
{ title: 'Child Node', key: `${treeNode.eventKey}-0` },
{ title: 'Child Node', key: `${treeNode.eventKey}-1` },
];
}
});
resolve();
return;
}, 1000);
});
}
return { treeData, handleCheck, tree, onLoadData };
},
});
</script>

0 comments on commit 9298b3c

Please sign in to comment.