Skip to content

Commit 53e94b6

Browse files
xiaodemenJustineo
authored andcommitted
docs: add a demo for cascader load prop
Change-Id: Icbafbb8a80c64150c23292465278ba4b89713616
1 parent 26add9a commit 53e94b6

File tree

4 files changed

+224
-42
lines changed

4 files changed

+224
-42
lines changed

one/docs/components/cascader.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@
4545

4646
[[ demo src="/demo/cascader/value-display.vue" ]]
4747

48+
### 数据项懒加载
49+
50+
配合使用 [`load`](#props-load) 属性和数据项中 `lazy` 属性来实现数据懒加载。
51+
52+
[[ demo src="/demo/cascader/lazy.vue" ]]
53+
4854
## API
4955

5056
### 属性
@@ -74,6 +80,7 @@
7480
| ``overlay-style`` | `string | Array | Object=` | - | 参考 [`Overlay`](./overlay) 组件的 [`overlay-style`](./overlay#props-overlay-style) 属性。 |
7581
| ``match`` | `(item, keyword, { ancestors }) => boolean | Array<[number, number]>` | - | 支持自定义高亮逻辑, 默认大小写不敏感,参考 [`Autocomplete`](./Autocomplete#自定义搜索逻辑)|
7682
| ``filter`` | `(item, keyword, { ancestors, offsets }) => boolean` | - | 支持自定义搜索命中逻辑,参考 [`Autocomplete`](./Autocomplete#自定义搜索逻辑)|
83+
| ``load`` | `Function` | - | [^load] |
7784

7885
^^^ui
7986
预设样式。
@@ -170,6 +177,26 @@
170177
+++
171178
^^^
172179

180+
^^^load
181+
182+
数据项懒加载,配合数据项上 `lazy` 属性使用。
183+
184+
```ts
185+
type Item {
186+
label: string,
187+
value: unknown,
188+
options?: Array<Item>,
189+
disabled?: boolean
190+
lazy?: boolean
191+
}
192+
193+
function load({
194+
parent?: Item,
195+
scope: 'descendants' | 'children'
196+
}): Item[] | void | Promise<Item[] | void>
197+
```
198+
^^^
199+
173200
### 插槽
174201

175202
| 名称 | 描述 |

one/docs/demo/cascader/lazy.vue

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
<template>
2+
<div>
3+
<veui-cascader
4+
v-model="value"
5+
:options="options"
6+
multiple
7+
:load="load"
8+
/>
9+
</div>
10+
</template>
11+
12+
<script>
13+
import { Cascader } from 'veui'
14+
15+
const options = [
16+
{
17+
label: '浙江',
18+
value: '浙江',
19+
options: [
20+
{
21+
label: '威海',
22+
value: '威海'
23+
},
24+
{
25+
label: '滨州',
26+
value: '滨州'
27+
},
28+
{
29+
label: '临沂',
30+
value: '临沂'
31+
},
32+
{
33+
label: '东营',
34+
value: '东营'
35+
},
36+
{
37+
label: '济南',
38+
value: '济南'
39+
}
40+
]
41+
},
42+
{
43+
label: '山东',
44+
value: '山东',
45+
lazy: true
46+
},
47+
{
48+
label: '上海',
49+
value: '上海',
50+
disabled: true
51+
},
52+
{
53+
label: '北京',
54+
value: '北京'
55+
},
56+
{
57+
label: '海外',
58+
value: '海外',
59+
disabled: true,
60+
options: [
61+
{
62+
label: '日本',
63+
value: '日本'
64+
}
65+
]
66+
}
67+
]
68+
69+
const hzChildren = [
70+
{
71+
label: '',
72+
value: ''
73+
},
74+
{
75+
label: '',
76+
value: ''
77+
}
78+
]
79+
80+
const getSdChildren = (full) => [
81+
{
82+
label: '菏泽',
83+
value: '菏泽',
84+
lazy: true,
85+
...(full ? { options: hzChildren } : null)
86+
},
87+
{
88+
label: '潍坊',
89+
value: '潍坊',
90+
options: [
91+
{
92+
label: '',
93+
value: ''
94+
},
95+
{
96+
label: '',
97+
value: ''
98+
}
99+
]
100+
},
101+
{
102+
label: '泰山',
103+
value: '泰山',
104+
// load no data
105+
...(full ? null : { lazy: true })
106+
},
107+
{
108+
label: '烟台',
109+
value: '烟台',
110+
disabled: true
111+
}
112+
]
113+
114+
export default {
115+
components: {
116+
'veui-cascader': Cascader
117+
},
118+
data () {
119+
return {
120+
value: null,
121+
options
122+
}
123+
},
124+
methods: {
125+
load: ({ parent, scope }) => {
126+
return new Promise((resolve) => {
127+
setTimeout(() => {
128+
let isFull
129+
switch (scope) {
130+
case 'children':
131+
isFull = false
132+
break
133+
case 'descendants':
134+
isFull = true
135+
break
136+
default:
137+
console.warn('Not supported.')
138+
resolve()
139+
return
140+
}
141+
142+
resolve(
143+
parent
144+
? {
145+
菏泽: hzChildren,
146+
山东: getSdChildren(isFull)
147+
}[parent.value]
148+
: undefined
149+
)
150+
}, 1000)
151+
})
152+
}
153+
}
154+
}
155+
</script>

package-lock.json

Lines changed: 37 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"@vue/runtime-dom": "^3.2.31",
2929
"babel-eslint": "^10.1.0",
3030
"babel-plugin-lodash": "^3.3.4",
31-
"babel-plugin-veui": "^2.7.2",
31+
"babel-plugin-veui": "^2.7.3",
3232
"cheerio": "^1.0.0-rc.10",
3333
"dls-graphics": "^1.0.0-alpha.3",
3434
"dls-icons-vue": "^2.6.0",
@@ -88,10 +88,10 @@
8888
"typescript": "^4.6.2",
8989
"unist-util-remove": "^1.0.1",
9090
"unist-util-visit": "^1.4.0",
91-
"veui": "^2.7.2",
92-
"veui-loader": "^2.7.2",
93-
"veui-theme-dls": "^2.7.2",
94-
"veui-theme-dls-icons": "^2.7.2",
91+
"veui": "^2.7.3",
92+
"veui-loader": "^2.7.3",
93+
"veui-theme-dls": "^2.7.3",
94+
"veui-theme-dls-icons": "^2.7.3",
9595
"vue-awesome": "^4.5.0",
9696
"vue-frag": "^1.4.0",
9797
"vue-i18n": "^8.16.0",

0 commit comments

Comments
 (0)