<template>
{{treeData}}
<a-tree-select
v-model:value="value"
v-model:searchValue="searchValue"
tree-data-simple-mode
tree-checkable
multiple
style="width: 100%"
:dropdown-style="{ maxHeight: '400px', overflow: 'auto' }"
:tree-data="treeData"
placeholder="Please select"
:load-data="onLoadData"
treeNodeFilterProp ='title'
>
<!-- <template #title="{ value: val, title }">
<b v-if="val === '111'" style="color: #08c">3</b>
<template v-else>
<template
v-for="(fragment, i) in title
.toString()
.split(new RegExp(`(?<=${searchValue})|(?=${searchValue})`, 'i'))"
>
<span
v-if="fragment.toLowerCase() === searchValue.toLowerCase()"
:key="i"
style="color: #08c"
>
{{ fragment }}11
</span>
<template v-else>{{ fragment }}</template>
</template>
</template>
</template> -->
</a-tree-select>
</template>
<script lang="ts">
import type { TreeSelectProps } from 'ant-design-vue';
import { defineComponent, ref, watch } from 'vue';
export default defineComponent({
setup() {
const value = ref<string>();
const treeData = ref<TreeSelectProps['treeData']>([
{ id: 1, pId: 0, value: '1', title: 'Expand to load' },
{ id: 2, pId: 0, value: '2', title: 'Expand to load' },
{ id: 3, pId: 0, value: '3', title: 'Tree Node', isLeaf: true },
]);
watch(value, () => {
console.log(value.value);
console.log('treeData',treeData.value)
});
const genTreeNode = (parentId: number, isLeaf = false): TreeSelectProps['treeData'][number] => {
const random = Math.random().toString(36).substring(2, 6);
return {
id: random,
pId: parentId,
value: random,
title: isLeaf ? 'Tree Node' : 'Expand to load',
isLeaf,
};
};
const onl oadData = (treeNode: TreeSelectProps['treeData'][number]) => {
return new Promise(resolve => {
const { id } = treeNode.dataRef;
setTimeout(() => {
treeData.value = treeData.value.concat([
genTreeNode(id, false),
genTreeNode(id, true),
genTreeNode(id, true),
]);
console.log(treeData.value);
resolve(true);
}, 300);
});
};
return {
searchValue: ref(''),
value,
treeData,
genTreeNode,
onl oadData,
};
},
});
</script>
标签:const,treeData,random,genTreeNode,value,test,id
From: https://www.cnblogs.com/gzeal/p/17128763.html