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