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/coordinate.vue

52 lines
1.2 KiB

<docs>
---
order: 6
title:
zh-CN: 联动
en-US: Coordinate
---
## zh-CN
省市联动是典型的例子
推荐使用 [Cascader](/components/cascader-cn/)
## en-US
Coordinating the selection of provinces and cities is a common use case and demonstrates how selection can be coordinated.
Using the [Cascader](/components/cascader) component is strongly recommended instead as it is more flexible and capable.
</docs>
<template>
<a-space>
<a-select
v-model:value="province"
style="width: 120px"
:options="provinceData.map(pro => ({ value: pro }))"
></a-select>
<a-select
v-model:value="secondCity"
style="width: 120px"
:options="cities.map(city => ({ value: city }))"
></a-select>
</a-space>
</template>
<script lang="ts" setup>
import { computed, ref, watch } from 'vue';
const provinceData = ['Zhejiang', 'Jiangsu'];
const cityData = {
Zhejiang: ['Hangzhou', 'Ningbo', 'Wenzhou'],
Jiangsu: ['Nanjing', 'Suzhou', 'Zhenjiang'],
};
const province = ref(provinceData[0]);
const secondCity = ref(cityData[province.value][0]);
const cities = computed(() => {
return cityData[province.value];
});
watch(province, val => {
secondCity.value = cityData[val][0];
});
</script>