✨ feature: emit handler added
This commit is contained in:
parent
f468fff7e4
commit
645b952c9f
|
@ -8,17 +8,22 @@ const props = withDefaults(defineProps<IVAccordion>(), {
|
||||||
value: null,
|
value: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Define the event emitter for v-model binding
|
||||||
const emit = defineEmits([
|
const emit = defineEmits([
|
||||||
'update:value',
|
'update:value',
|
||||||
])
|
])
|
||||||
|
|
||||||
|
// Local reactive value to sync with the parent v-model
|
||||||
const localValue = ref(props.value);
|
const localValue = ref(props.value);
|
||||||
|
|
||||||
|
// Watch for external changes to the prop and update localValue accordingly
|
||||||
watch(() => props.value, (newVal) => {
|
watch(() => props.value, (newVal) => {
|
||||||
if(localValue.value !== newVal) {
|
if(localValue.value !== newVal) {
|
||||||
localValue.value = newVal;
|
localValue.value = newVal;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Watch for internal changes to localValue and emit them to the parent
|
||||||
watch(localValue, (newVal) => {
|
watch(localValue, (newVal) => {
|
||||||
if(props.value !== newVal){
|
if(props.value !== newVal){
|
||||||
emit('update:value', newVal);
|
emit('update:value', newVal);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user