Skip to content

Cascader 级联选择

提示

如果不需要通过接口获取数据建议使用 AntDesignVue 中的自带的 Cascader 组件

代码演示

基础用法

vue
<template>
    <x-cascader
        v-model="selectedKeys"
        :level="3"
        :load-data="getOptions">
    </x-cascader>
</template>

<script setup>
import { ref } from 'vue'
import apis from '@/apis'

const selectedKeys = ref([])

async function getOptions() {
    return await apis.common.getOptions()
}
</script>

<style lang="less" scoped></style>

高级用法

vue
<template>
    <x-cascader
        v-model="selectedKeys"
        :level="3"
        :load-data="[getOptions, getOptions, getOptions]">
    </x-cascader>
</template>

<script setup>
import { ref } from 'vue'
import apis from '@/apis'

const selectedKeys = ref([])

async function getOptions() {
    return await apis.common.getOptions()
}
</script>

<style lang="less" scoped></style>

API

Props

参数说明类型默认值
model-value(v-model)内容array[]
load-data加载数据functionarray-
level最大层级,loadData 为 function 类型时可以用它来控制数据的最深层级;loadData 为 array 类型时,通过数组长度自动计算最多层级number1
field-names自定义 optionslabel value children 的字段object{ label: 'label', value: 'value', children: 'children' }

Events

事件名说明回调参数
change选中项变化时触发{value, selectedOptions}

本文档内容版权为 XYAdmin 作者所有,保留所有权利。