naive-ui/demo/documentation/components/cascader/enUS/singleLeafOnlyLazy.demo.md
07akioni 487001d697 build: add changelog to site, refactor loader based on suffix
.demo.md for component demo
.demo-entry.md for demo entry
.md for common docs
2020-08-19 23:30:04 +08:00

651 B

Async Single (Leaf Only)

<n-cascader
  v-model="value"
  placeholder="Please Select Something"
  remote
  :on-load="handleLoad"
/>
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)
    }
  }
}