perf: refs #8725 handle axios.error
This commit is contained in:
parent
a01f02e31b
commit
095f01717d
|
@ -1,6 +1,15 @@
|
|||
<script setup>
|
||||
import axios from 'axios';
|
||||
import { onMounted, onUnmounted, computed, ref, watch, nextTick, useAttrs } from 'vue';
|
||||
import {
|
||||
onMounted,
|
||||
onUnmounted,
|
||||
computed,
|
||||
ref,
|
||||
watch,
|
||||
nextTick,
|
||||
useAttrs,
|
||||
inject,
|
||||
} from 'vue';
|
||||
import { onBeforeRouteLeave, useRouter, useRoute } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { useQuasar } from 'quasar';
|
||||
|
@ -13,7 +22,7 @@ import VnConfirm from './ui/VnConfirm.vue';
|
|||
import { tMobile } from 'src/composables/tMobile';
|
||||
import { useArrayData } from 'src/composables/useArrayData';
|
||||
import { getDifferences, getUpdatedValues } from 'src/filters';
|
||||
|
||||
const app = inject('app');
|
||||
const { push } = useRouter();
|
||||
const quasar = useQuasar();
|
||||
const state = useState();
|
||||
|
@ -134,12 +143,15 @@ const defaultButtons = computed(() => ({
|
|||
...$props.defaultButtons,
|
||||
}));
|
||||
|
||||
const submitForm = () => {
|
||||
myForm.value.validate().then((success) => {
|
||||
if (success) {
|
||||
save();
|
||||
const submitForm = async () => {
|
||||
const valid = await myForm.value.validate();
|
||||
if (valid) {
|
||||
try {
|
||||
await save();
|
||||
} catch (error) {
|
||||
app.config.errorHandler(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(async () => {
|
||||
|
@ -237,10 +249,9 @@ async function save() {
|
|||
const method = $props.urlCreate ? 'post' : 'patch';
|
||||
const url =
|
||||
$props.urlCreate || $props.urlUpdate || $props.url || arrayData.store.url;
|
||||
let response;
|
||||
|
||||
if ($props.saveFn) response = await $props.saveFn(body);
|
||||
else response = await axios[method](url, body);
|
||||
const response = await Promise.resolve(
|
||||
$props.saveFn ? $props.saveFn(body) : axios[method](url, body),
|
||||
);
|
||||
|
||||
if ($props.urlCreate) notify('globals.dataCreated', 'positive');
|
||||
|
||||
|
|
Loading…
Reference in New Issue