Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

194
Vistas
Calling api request after Complete other requests
beforeTabSwitch: async (tab) => {

            let flag = false;
            if (tab === 'PAYMENT') {
                if (this.isManualValidated) {
                    flag = true;
                    this.savePayment().then((response) => {
                        this.placeOrder();
                    });


                }
            } 
            return flag;
        }
savePayment: async function () {
            this.$http.post(this.savePaymentRoute)
                .then(response => {
                    await this.getOrderSummary();
                })
                .catch(error => {
                });
},
placeOrder: async function () {
            this.$http.post(this.saveOrderRoute)
                .then(response => {
                })
                .catch(error => {
                    console.log('placeOrder | ' + error);
                })
        },

When Place Order Button Clicked beforeTabSwitch() which validate data & then call savePayment() . as savePayment request is complete then call getOrderSummary() then call placeOrder() request.

Call in Order: savePayment() > getOrderSummary() > placeOrder()

but the issue is after execute savePayment() immediately placeOrder() execution start after complete then getOrderSummary() execute which is wrong.

i already try with Promises, callback but same issue. enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You need to start writing some clean code. And you should either use promises approach or async-await approach. I hope this code help you:

beforeTabSwitch: async (tab) => {
    if (tab !== 'PAYMENT') {
        return false;
    }
    
    if (!this.isManualValidated) {
        return false;
    }

    try {
        const response = await this.savePayment();
        this.placeOrder();
    } catch (error) {
        console.log(error);
    }

    return true;
},
savePayment: async function () {
    try {
        const paymentResponse = await this.$http.post(this.savePaymentRoute);
        const summaryResponse = await this.getOrderSummary();
    } catch (error) {
        console.log(error);
    }
},
placeOrder: async function () {
    try {
        const response = await this.$http.post(this.saveOrderRoute);
    } catch (error) {
        console.log('placeOrder | ' + error);
    }
},
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda