How can I use the boolean response from axios to dynamically disable a button in a Vue application?

Despite reading numerous answered questions on Stack Overflow, I am still struggling to resolve this issue. My problem arises from trying to call a function in Vue that returns a promise instead of the expected boolean value needed to disable a button. How can I convert the returned promise into a boolean?

                        <v-btn
                        medium
                        color="white"
                        style="overflow: hidden"
                        @click="runValidationTaskNow(index)"
                        :loading="isRunTaskBtnDisabled(index)"
                        :disabled="isRunTaskBtnDisabled(index)"
                        >RUN NOW

......

Within my methods, I utilize the mentioned function for disabling and loading.

 async isRunTaskBtnDisabled(index) {
   const Status = await Util.checkFeatureEnabled("Validate "+this.validationTasks[index].productName);

  // Status.then(value => value);
   return Status;

The checkFeatureEnabled function called above resides in another file, as shown below:

async checkFeatureEnabled(featureName){
const reqURL = process.env.VUE_APP_GUIDE_UTILITY_SERVICES_HOST + `/api/checkFeatureEnabled/` + featureName;
console.log("reqURL", reqURL);
return await Axios(reqURL, { method: "GET", withCredentials: true })
    .then((response) => {
      console.log("ui"+response.data);
    return response.data;
}).catch((error) => console.log(error));  

In this code snippet, the response.data contains either true or false values retrieved accurately from the database.

Answer №1

modify this section

return await Axios(reqURL, { method: "GET", withCredentials: true })
    .then((response) => {
      console.log("ui"+response.data);
    return response.data;
}).catch((error) => console.log(error));  

into the following:

try {
  const response = await Axios(reqURL, { method: 'GET', withCredentials: true })
  console.log('ui' + response.data)
  return response.data
} catch (e) {
  console.log(e)
  return something
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What are the steps for setting up API REST calls proxy for a frontend hosted on Netlify?

While testing locally, I am able to successfully post a call and access it through Netlify. However, once I host the frontend app on Netlify, the POST Proxy is being set to the Netlify URL. The hosted URL: Upon clicking "Sign Up" and then clicking on "Si ...

Encountering an error in Vue.js where a "cannot read property of undefined" message is displayed when attempting to use v

While attempting to use v-model on an array item's property, I encountered the error message "[Vue warn]: Error in render function: 'TypeError: Cannot read property 'viewFood' of undefined' when loading the page. This resulted in a ...

Using either Model or Controller for Vuetify validation

My goal is to implement validation in my Vuetify form, using data from my Model or Controller, and display an alert message. Here is a snippet from my .vue file: <v-row dense> <v-col cols="3"> <v-text-field dense outli ...

The try and catch block in JavaScript is failing to correctly capture the HTTP status

I have a function that successfully posts JSON to an API endpoint. Here is the code I am using: function sendValuesPageLoad(){ var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function () { try { if (xhr.readyState === ...

What is the process for retrieving the component along with the data?

As I work on compiling a list of div elements that require content from my firebase cloud storage, I find myself unsure about how to effectively run the code that retrieves data from firebase and returns it in the form of MyNotes. Consider the following: ...

Turned off jquery on a specific div in order to resolve compatibility problems with Vue.js

Currently, I am working on a Drupal project which includes JQuery in all pages. We have recently introduced Vue.js for creating dynamic components directly in the HTML pages (not for building a single-page application). However, we are facing an issue whe ...

jQuery - The .always() callback is triggering prematurely

I am currently developing a client-side JavaScript application that is designed to retrieve data from a CSV file, make multiple API calls for each row, and then save the results back to the CSV. The main challenge I am facing is how to coordinate these req ...

In React, I am unable to invoke a function that has been assigned to an element

import React from "react"; import shortid from "shortid"; export default class App extends React.Component { state = { items: [], text: "" }; handleTextChange = event => { this.setState({ text: event.target.value }); }; ...

problem involving iview table when rendering data

Assuming I have a data object structured like this: data: [ { name: { nikeName: 'sam', realName: 'sanjay' }, age: 18, address: 'New York No. 1 Lake Park', date: '2016-10-03' }, { name: { nikeName: 'roy', r ...

Resolved issue with maintaining scroll position after adjustments to scroll height

Currently, I am in the process of creating a chatroom that includes pagination. The issue I am encountering is related to loading old messages when the scroll height reaches 0. However, unlike platforms such as Facebook and Slack, even when the scroll he ...

is there a way to modify the background color of a div element by comparing values in javascript?

Is there a way to dynamically update the background color of a div element within a table based on values stored in a json array from a database? ...

When providing a page URL, wkhtmltopdf is able to execute JavaScript code, however, this functionality is not available when using a static

I've implemented a native javascript plugin to highlight specific text on a webpage. When I provide wkhtmltopdf with the page's URL, the highlighting is preserved in the resulting PDF file. However, if I save the webpage as an HTML file and the ...

A step-by-step guide to accessing Chrome performance metrics using JavaScript

By utilizing Chrome Dev Tools, I am able to perform the following actions: Begin by opening Chrome Dev Tools (simply right click on any page in Chrome and select "inspect") Navigate to the "performance" tab Click on the record button Interact with a butt ...

Calling http.get one after the other without knowing the length of the list

Suppose I have a list of URLs as follows: var myurls = ['http://server1.com', 'http://server2.com', 'http:sever2.com', etc ] Each URL is considered a "fallback" and should only be used if the previous one is unreachable. Thi ...

Is there a quick way in ES6 to assign member functions as event listeners?

This question is unique and not a repetition of the query posed in How to access the correct `this` context inside a callback? Although some answers may overlap, the Question at hand differs. The comments below the answers indicate varied solutions, parti ...

What is the best way to update the backdrop-filter using JavaScript?

Hey there, I'm having trouble changing the backdrop-filter using javascript. Could someone please assist me with this issue? Thanks! <html> <head> <title>An Issue</title> <style> #div { width: 120px; height: 120px; ...

Turn off the nicescroll scroll bar that appears as a default feature

Is there a way to disable the nicescroll scroll bar that appears in red by default on my html page? It's causing issues with zooming in and breaking the layout. ...

What is the best practice for making a gRPC call within a Typescript Vue.Js component?

Upon reviewing the grpc documentation, I discovered that proto files can be used to generate Node (Javascript), Typescript with the assistance of grpc_tools_node_protoc_ts, and grpc-web. Given that performance is not a critical factor in my particular situ ...

JavaScript's efficient way to target multiple class names

My goal is to extract and process JSON data into specific instances of a class named "slide_content" I want to achieve something like this: slide_content[0] Unfortunately, JS does not offer a method like getElementByClass(). The relevant API data can b ...

The code functions perfectly in the Adobe Dreamweaver Preview, but unfortunately, it is not compatible with Chrome

In the process of creating a website using Adobe Dreamweaver over the past few days, I encountered an issue with JavaScript that should activate upon scrolling. Interestingly, the script works perfectly fine when accessed through this link (), but fails t ...