naive-ui/demo/documentation/components/cascader/enUS/single-leaf-only-lazy.demo.md

38 lines
651 B
Markdown
Raw Normal View History

2020-02-04 21:44:48 +08:00
# Async Single (Leaf Only)
2019-10-23 13:56:20 +08:00
```html
<n-cascader
v-model="value"
placeholder="Please Select Something"
2020-02-04 21:44:48 +08:00
remote
2019-10-23 13:56:20 +08:00
:on-load="handleLoad"
/>
```
```js
function genChildren (option) {
const children = []
const label = option.label || 'root'
for (let i = 0; i <= option.depth; ++i) {
children.push({
label: label + '_' + i,
value: label + '_' + i,
isLeaf: option.depth === 3
})
}
return children
}
export default {
data () {
return {
value: null
}
},
methods: {
handleLoad (option, resolve) {
window.setTimeout(() => {
resolve(genChildren(option))
}, 1000)
}
}
}
```