CascadingRegionSelector.vue
2.32 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<template>
<el-cascader
v-model="selectedValue"
:options="regionOptions"
:props="cascaderProps"
:placeholder="placeholder"
:clearable="clearable"
:show-all-levels="showAllLevels"
:style="style"
@change="handleChange"
></el-cascader>
</template>
<script>
// 地区数据
const regionOptions = [
{
value: '江苏省',
label: '江苏省',
children: [
{
value: '南京市',
label: '南京市',
children: [
{ value: '玄武区', label: '玄武区' },
{ value: '秦淮区', label: '秦淮区' },
{ value: '建邺区', label: '建邺区' },
{ value: '鼓楼区', label: '鼓楼区' },
{ value: '浦口区', label: '浦口区' },
{ value: '栖霞区', label: '栖霞区' },
{ value: '雨花台区', label: '雨花台区' },
{ value: '江宁区', label: '江宁区' },
{ value: '六合区', label: '六合区' },
{ value: '溧水区', label: '溧水区' },
{ value: '高淳区', label: '高淳区' }
]
},
{
value: '南通市',
label: '南通市',
children: [
{ value: '崇川区', label: '崇川区' },
{ value: '港闸区', label: '港闸区' }
]
},
{
value: '苏州市',
label: '苏州市',
children: [
{ value: '姑苏区', label: '姑苏区' },
{ value: '虎丘区', label: '虎丘区' }
]
}
]
}
]
export default {
name: 'CascadingRegionSelector',
props: {
value: {
type: [String, Array],
default: ''
},
placeholder: {
type: String,
default: '请选择区域'
},
clearable: {
type: Boolean,
default: true
},
showAllLevels: {
type: Boolean,
default: true
},
style: {
type: Object,
default: () => ({})
}
},
data() {
return {
selectedValue: this.value,
regionOptions,
cascaderProps: {
value: 'value',
label: 'label',
children: 'children',
checkStrictly: true
}
}
},
watch: {
value(newVal) {
this.selectedValue = newVal
}
},
methods: {
handleChange(value) {
this.$emit('input', value)
this.$emit('change', value)
}
}
}
</script>