You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ant-design-vue/components/select/demo/field-names.vue

72 lines
1.2 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<docs>
---
order: 0
title:
zh-CN: 自定义 labelvalueoptions 字段
en-US: Custom `label` `value` `options` field
---
## zh-CN
方便数据结构转换
仅支持 options 传递不支持 a-select-option 构造节点
## en-US
Easy data structure conversion.
Only options passing is supported, a-select-option construction node is not supported.
</docs>
<template>
<a-select
ref="select"
v-model:value="value"
style="width: 120px"
:options="options"
:field-names="{ label: 'name', value: 'id', options: 'children' }"
@focus="focus"
@change="handleChange"
></a-select>
</template>
<script lang="ts" setup>
import type { SelectProps } from 'ant-design-vue';
import { ref } from 'vue';
const value = ref('lucy');
const options = ref<SelectProps['options']>([
{
id: 'jack',
name: 'Jack',
children: [
{
id: 'small jack',
name: 'samll Jack',
},
],
},
{
id: 'lucy',
name: 'Lucy',
},
{
id: 'disabled',
name: 'Disabled',
disabled: true,
},
{
id: 'yiminghe',
name: 'Yiminghe',
},
]);
const focus = () => {
console.log('focus');
};
const handleChange = (value: string) => {
console.log(`selected ${value}`);
};
</script>