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

151
Visualizações
If statement not executing in vue 3 async function

I'm busy with a client management system project, but I'm having a bit of trouble with my async functions. I do the api calls in a seperate js file APIController\api.js and in the UserForm.vue component I have an async function createUser that is supposed to call two functions ported into the component as props. The code is as follows:

I have the ref and APIController imported:

import { ref } from 'vue';
import APIController from '@\Controllers\api';

I have the props imported:

props: ["toggleForm", "fetchUsers", "userId"],

And finally my setup function with the async function:

setup(props){
        const user = ref({});
        const createUser = async () => {
            const success = await APIController.CreateUser(user.value.name, user.value.phone, user.value.address);
            if(success){
                props.fetchUsers();
                props.toggleForm();
            }
        }
    }

Here's the APIController.CreateUser() function for further clarification:

CreateUser: (name, phone, address) => {
        if(
            name == "" ||
            phone == "" ||
            address == ""
        ) {
            return false;
        } else {

            fetch(API_BASE + "/users/create", {
                method: "POST",
                headers: {
                    "Content-Type": "application/json"
                },
                body: JSON.stringify({ name, phone, address })
            }).then(response => response.json())
            .then(data => {
                if(data.success){
                    return data.response.user;
                } else {
                    throw data.response.error;
                }
            }).catch(err => {
                alert(err);
            });
        }
    },

The function executes the api call perfectly, but the if statement doesn't execute at all. Any help will be appreciated. Thank you.

about 4 years ago · Juan Pablo Isaza
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