index.vue
1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<template>
<el-cascader :options="optionsData" v-model="selectedOptions" @change="handleChange" />
</template>
<script setup lang="ts" name="china-area">
import { provinceAndCityData, provinceAndCityDataPlus, regionData, regionDataPlus } from '/@/utils/chinaArea';
const emit = defineEmits(['update:value', 'change']);
const optionsData = ref();
const props = defineProps({
// 当前的值
modelValue: String,
// 类型 (二级联动,三级联动)
type: {
type: Number,
default: 3,
},
plus: {
type: Boolean,
default: false,
},
});
const selectedOptions = computed({
get: () => {
return props.modelValue?.split(',');
},
set: (val) => {
emit('update:value', val?.join(','));
},
});
const handleChange = (value: String[]) => {
emit('change', value.join(','));
};
onMounted(() => {
const { plus, type } = props;
if (plus) {
optionsData.value = type === 2 ? provinceAndCityDataPlus : regionDataPlus;
} else {
optionsData.value = type === 2 ? provinceAndCityData : regionData;
}
});
</script>