watchEffect -> watch

This commit is contained in:
yoon 2025-02-03 15:07:29 +09:00
parent 8ceddc8036
commit a4cb9936ab

View File

@ -16,7 +16,7 @@
</template>
<script setup>
import { ref, watch, watchEffect } from 'vue';
import { ref, watch } from 'vue';
const props = defineProps({
title: {
@ -69,13 +69,16 @@ const props = defineProps({
const emit = defineEmits(['update:data']);
const selectData = ref(props.value);
watchEffect(() => {
if (props.isCommon && props.data.length > 0) {
selectData.value = props.data[0].value; //
} else {
selectData.value = props.value; //
// data
watch(() => props.data, (newData) => {
if (props.isCommon && newData.length > 0) {
selectData.value = newData[0].value;
emit('update:data', selectData.value);
}
emit('update:data', selectData.value);
})
}, { immediate: true });
// selectData
watch(selectData, (newValue) => {
emit('update:data', newValue);
});
</script>