javascript - 如何从 axios 返回布尔值以禁用 vue 中的按钮
问题描述
我阅读了堆栈溢出中几乎所有已回答的问题来解决这个问题,但我仍然无法解决这个问题。我正在尝试调用一个函数来禁用我在 vue 中的按钮,并且该函数返回一个承诺而不是布尔值。我怎样才能在这里得到一个布尔值?
<v-btn
medium
color="white"
style="overflow: hidden"
@click="runValidationTaskNow(index)"
:loading="isRunTaskBtnDisabled(index)"
:disabled="isRunTaskBtnDisabled(index)"
>RUN NOW
……
在我的方法中,我调用了我在禁用和加载中提到的这个函数。
async isRunTaskBtnDisabled(index) {
const Status = await Util.checkFeatureEnabled("Validate "+this.validationTasks[index].productName);
// Status.then(value => value);
return Status;
并且 checkFeatureEnabled 来自下面给出的另一个文件
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));
这里response.data
是真还是假;我从我的数据库中得到了正确的结果。
解决方案
改变这部分
return await Axios(reqURL, { method: "GET", withCredentials: true })
.then((response) => {
console.log("ui"+response.data);
return response.data;
}).catch((error) => console.log(error));
对此:
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
}
推荐阅读
- python - 为什么-1会在pandas dataframe中导致关键错误重置其索引以及如何使其工作
- javascript - 在 Web 组件布局中添加/删除项目的标准方法是什么?
- html - Jekyll Kramdown 保留新线路
- angular - 如何将我的 ionic 应用程序连接到同一页面中的两个不同 API URL?如何将 id 从第一个 url 的数据传递到第二个 url?
- swift - 为什么 ~= 不适用于枚举和字符串?
- python - Python 在 Visual Studio Code 上无法正常运行
- angular - 为什么主题订阅在 Angular 9 中不起作用
- c# - 如果并行调用不同数量的线程,为什么我会得到不同的总和?
- python - 如何使用re分别提取重复数据
- php - 如何根据数据库值显示特定的 div?