feat: add Tree LoadData demo
This commit is contained in:
parent
8d22231a5f
commit
9298b3c988
|
|
@ -26,10 +26,13 @@
|
||||||
class="w-1/3"
|
class="w-1/3"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="flex">
|
||||||
|
<BasicTree title="异步树" :treeData="tree" class="w-1/3" :load-data="onLoadData" />
|
||||||
|
</div>
|
||||||
</PageWrapper>
|
</PageWrapper>
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { defineComponent } from 'vue';
|
import { defineComponent, ref } from 'vue';
|
||||||
import { BasicTree } from '/@/components/Tree/index';
|
import { BasicTree } from '/@/components/Tree/index';
|
||||||
import { treeData } from './data';
|
import { treeData } from './data';
|
||||||
import { PageWrapper } from '/@/components/Page';
|
import { PageWrapper } from '/@/components/Page';
|
||||||
|
|
@ -40,7 +43,34 @@
|
||||||
function handleCheck(checkedKeys, e) {
|
function handleCheck(checkedKeys, e) {
|
||||||
console.log('onChecked', 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>
|
</script>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue