update late selection options

This commit is contained in:
2023-01-25 12:09:55 +10:00
parent 1a3c22bf13
commit 71a47f2f84

View File

@@ -26,7 +26,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, useSlots, onMounted } from "vue"; import { useSlots, onMounted, computed, watch } from "vue";
const props = defineProps({ const props = defineProps({
modelValue: { modelValue: {
@@ -78,11 +78,17 @@ const handleBlur = (event) => {
} }
}; };
onMounted(() => { const initialOptions = computed(() => {
return props.options;
});
watch(initialOptions, () => {
if ( if (
props.modelValue.length == 0 || props.modelValue.length > 0 &&
props.modelValue in Object.keys(props.options) == false props.modelValue in Object.keys(props.options) == true
) { ) {
emits("update:modelValue", props.modelValue);
} else if (Object.keys(props.options).length > 0) {
emits("update:modelValue", Object.keys(props.options)[0]); emits("update:modelValue", Object.keys(props.options)[0]);
} }
}); });