feature: emit handler added

This commit is contained in:
Paul Valerie GOMA 2025-07-21 17:00:18 +02:00
parent f468fff7e4
commit 645b952c9f

View File

@ -8,17 +8,22 @@ const props = withDefaults(defineProps<IVAccordion>(), {
value: null,
});
// Define the event emitter for v-model binding
const emit = defineEmits([
'update:value',
])
// Local reactive value to sync with the parent v-model
const localValue = ref(props.value);
// Watch for external changes to the prop and update localValue accordingly
watch(() => props.value, (newVal) => {
if(localValue.value !== newVal) {
localValue.value = newVal;
}
});
// Watch for internal changes to localValue and emit them to the parent
watch(localValue, (newVal) => {
if(props.value !== newVal){
emit('update:value', newVal);