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

150
Vistas
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 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