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