let checkResult; if(this.formEntity.ExamType==0){ checkResult = this.checktypetask(this.formEntity.ExamType, this.formEntity.DrillOrgIDarr, this.formEntity.PostId) }else{ checkResult = this.checktypetask(this.formEntity.ExamType, this.formEntity.ByCheckOrgIDs, this.formEntity.PostId) } console.log(checkResult, 'checkResultcheckResultcheckResult') if(!checkResult){ console.log(checkResult, 'checkResultcheckResultcheckResult') return }checkResult返回的是一个promise对象,怎么拿到他的返回值
时间: 2024-03-27 08:34:51 浏览: 83
要获取 `checkResult` 的返回值,可以使用 `async/await` 或者 `.then()` 方法。
使用 `async/await`:
```
async function someFunction() {
let checkResult;
if (this.formEntity.ExamType == 0) {
checkResult = await this.checktypetask(this.formEntity.ExamType, this.formEntity.DrillOrgIDarr, this.formEntity.PostId);
} else {
checkResult = await this.checktypetask(this.formEntity.ExamType, this.formEntity.ByCheckOrgIDs, this.formEntity.PostId);
}
console.log(checkResult, 'checkResultcheckResultcheckResult');
if (!checkResult) {
console.log(checkResult, 'checkResultcheckResultcheckResult');
return;
}
// handle the result here
}
```
使用 `.then()` 方法:
```
function someFunction() {
let checkResult;
if (this.formEntity.ExamType == 0) {
checkResult = this.checktypetask(this.formEntity.ExamType, this.formEntity.DrillOrgIDarr, this.formEntity.PostId);
} else {
checkResult = this.checktypetask(this.formEntity.ExamType, this.formEntity.ByCheckOrgIDs, this.formEntity.PostId);
}
checkResult.then((result) => {
console.log(result, 'checkResultcheckResultcheckResult');
if (!result) {
console.log(result, 'checkResultcheckResultcheckResult');
return;
}
// handle the result here
});
}
```
阅读全文