优化
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
<script setup>
|
||||
import { regionData, codeToText } from 'element-china-area-data'
|
||||
import { onMounted } from 'vue';
|
||||
const emit = defineEmits(['change'])
|
||||
|
||||
const placeholder = ref('')
|
||||
@@ -28,8 +29,36 @@ function setValue(arr) {
|
||||
selectedOptions.value = arr
|
||||
}
|
||||
|
||||
// 使用文字设置地区
|
||||
function textSetValue(arr) {
|
||||
console.log(arr)
|
||||
selectedOptions.value = TextToCode(arr)
|
||||
}
|
||||
|
||||
// 文字转省市区code
|
||||
function TextToCode(arr) {
|
||||
const n = []
|
||||
for (let item of regionData) {
|
||||
if (item.label == arr[0]) {
|
||||
n[0] = item.value
|
||||
for (let l of item.children) {
|
||||
if (l.label == arr[1]) {
|
||||
n[1] = l.value
|
||||
for (let i of l.children) {
|
||||
if (i.label == arr[2]) {
|
||||
n[2] = i.value
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
placeholder,
|
||||
setValue
|
||||
setValue,
|
||||
textSetValue
|
||||
})
|
||||
</script>
|
||||
Reference in New Issue
Block a user