feat(ui): support preloaded options for selects

This commit is contained in:
Tim
2025-07-10 13:53:30 +08:00
parent 0b5883cc20
commit 7c7f54779d
4 changed files with 91 additions and 23 deletions

View File

@@ -71,7 +71,8 @@ export default {
remote: { type: Boolean, default: false },
menuClass: { type: String, default: '' },
optionClass: { type: String, default: '' },
showSearch: { type: Boolean, default: true }
showSearch: { type: Boolean, default: true },
initialOptions: { type: Array, default: () => [] }
},
emits: ['update:modelValue'],
setup(props, { emit }) {
@@ -80,7 +81,7 @@ export default {
const setSearch = (val) => {
search.value = val
}
const options = ref([])
const options = ref(Array.isArray(props.initialOptions) ? [...props.initialOptions] : [])
const loaded = ref(false)
const loading = ref(false)
const wrapper = ref(null)
@@ -136,6 +137,15 @@ export default {
}
}
watch(
() => props.initialOptions,
val => {
if (Array.isArray(val)) {
options.value = [...val]
}
}
)
watch(open, async val => {
if (val) {
if (props.remote) {