2020-03-23 03:00:24 +00:00
|
|
|
<template>
|
2021-08-17 14:03:49 +00:00
|
|
|
<a-tree
|
|
|
|
v-model:expandedKeys="expandedKeys"
|
|
|
|
v-model:selectedKeys="selectedKeys"
|
2021-08-18 01:14:01 +00:00
|
|
|
:load-data="onLoadData"
|
2021-08-17 14:03:49 +00:00
|
|
|
:tree-data="treeData"
|
2021-08-18 01:14:01 +00:00
|
|
|
/>
|
2020-03-23 03:00:24 +00:00
|
|
|
</template>
|
2021-08-17 14:03:49 +00:00
|
|
|
<script lang="ts">
|
2021-08-18 01:14:01 +00:00
|
|
|
import { defineComponent, ref } from 'vue';
|
2021-08-17 14:03:49 +00:00
|
|
|
import { TreeDataItem } from 'ant-design-vue/es/tree/Tree';
|
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
setup() {
|
2021-08-18 01:14:01 +00:00
|
|
|
const expandedKeys = ref<string[]>([]);
|
|
|
|
const selectedKeys = ref<string[]>([]);
|
|
|
|
const treeData = ref<TreeDataItem[]>([
|
|
|
|
{ title: 'Expand to load', key: '0' },
|
|
|
|
{ title: 'Expand to load', key: '1' },
|
|
|
|
{ title: 'Tree Node', key: '2', isLeaf: true },
|
|
|
|
]);
|
|
|
|
const onLoadData = (treeNode: any) => {
|
|
|
|
return new Promise((resolve: (value?: unknown) => void) => {
|
|
|
|
if (treeNode.dataRef.children) {
|
|
|
|
resolve();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
setTimeout(() => {
|
|
|
|
treeNode.dataRef.children = [
|
|
|
|
{ title: 'Child Node', key: `${treeNode.eventKey}-0` },
|
|
|
|
{ title: 'Child Node', key: `${treeNode.eventKey}-1` },
|
|
|
|
];
|
|
|
|
treeData.value = [...treeData.value];
|
|
|
|
resolve();
|
|
|
|
}, 1000);
|
|
|
|
});
|
|
|
|
};
|
2021-08-17 14:03:49 +00:00
|
|
|
return {
|
|
|
|
expandedKeys,
|
|
|
|
selectedKeys,
|
2021-08-18 01:14:01 +00:00
|
|
|
treeData,
|
|
|
|
onLoadData,
|
2021-08-17 14:03:49 +00:00
|
|
|
};
|
2020-11-23 08:39:09 +00:00
|
|
|
},
|
|
|
|
});
|
2020-10-19 09:17:10 +00:00
|
|
|
</script>
|