-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
Copy pathlazy.vue
76 lines (67 loc) · 1.56 KB
/
lazy.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<docs>
---
order: 9
title:
zh-CN: 动态加载选项
en-US: Load Options Lazily
---
## zh-CN
使用 `loadData` 实现动态加载选项。
> 注意:`loadData` 与 `showSearch` 无法一起使用。
## en-US
Load options lazily with `loadData`.
> Note: `loadData` cannot work with `showSearch`.
</docs>
<template>
<a-cascader
v-model:value="value"
:options="options"
:load-data="loadData"
placeholder="Please select"
change-on-select
/>
</template>
<script lang="ts">
import { defineComponent, ref } from 'vue';
import type { CascaderProps } from 'ant-design-vue';
export default defineComponent({
setup() {
const options = ref<CascaderProps['options']>([
{
value: 'zhejiang',
label: 'Zhejiang',
isLeaf: false,
},
{
value: 'jiangsu',
label: 'Jiangsu',
isLeaf: false,
},
]);
const loadData: CascaderProps['loadData'] = selectedOptions => {
const targetOption = selectedOptions[selectedOptions.length - 1];
targetOption.loading = true;
// load options lazily
setTimeout(() => {
targetOption.loading = false;
targetOption.children = [
{
label: `${targetOption.label} Dynamic 1`,
value: 'dynamic1',
},
{
label: `${targetOption.label} Dynamic 2`,
value: 'dynamic2',
},
];
options.value = [...options.value];
}, 1000);
};
return {
value: ref<string[]>([]),
options,
loadData,
};
},
});
</script>