Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

193
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda