diff --git a/src/components/FormModel.vue b/src/components/FormModel.vue index 426d99b9a..05c63d563 100644 --- a/src/components/FormModel.vue +++ b/src/components/FormModel.vue @@ -87,7 +87,7 @@ const $props = defineProps({ const emit = defineEmits(['onFetch', 'onDataSaved']); const modelValue = computed( () => $props.model ?? `formModel_${route?.meta?.title ?? route.name}` -); +).value; const componentIsRendered = ref(false); const arrayData = useArrayData(modelValue); const isLoading = ref(false); @@ -119,9 +119,10 @@ onMounted(async () => { // Podemos enviarle al form la estructura de data inicial sin necesidad de fetchearla state.set(modelValue, $props.formInitialData); - if ($props.autoLoad && !$props.formInitialData && $props.url) await fetch(); - else if (arrayData.store.data) updateAndEmit('onFetch', arrayData.store.data); - + if (!$props.formInitialData) { + if ($props.autoLoad && $props.url) await fetch(); + else if (arrayData.store.data) updateAndEmit('onFetch', arrayData.store.data); + } if ($props.observeFormChanges) { watch( () => formData.value, @@ -245,7 +246,13 @@ function updateAndEmit(evt, val, res) { emit(evt, state.get(modelValue), res); } -defineExpose({ save, isLoading, hasChanges }); +defineExpose({ + save, + isLoading, + hasChanges, + reset, + fetch, +});