This commit is contained in:
2023-10-11 09:34:39 +08:00
parent b541e8ae61
commit 79ca98a12b
10 changed files with 102 additions and 32 deletions

View File

@@ -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>