Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

149
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!