为什么我在 <pending> 从节点中的 EJS 文件调用函数时得到 Promise { }.js



下面是返回SQL查询结果的函数:

function getPriorityList(operatorId) {
try {
const result = Api.getApisDetail(operatorId);
return result;
} catch (error) {
console.log(error);
}
}  

你应该等待诺言实现

try this:

async function getPriorityList(operatorId) {
try {
const result = await Api.getApisDetail(operatorId);
return result;
} catch (error) {
console.log(error);
}
}

在这种情况下,承诺实现似乎是不正确的。试试这样做:

function getPriorityList(operatorId) {
Api.getApisDetail(operatorId).then((result) =>{
console.log(result);
return result;
}).catch((error)=>{
return error;
});
}

"Api.getApisDetail"在这种情况下,函数必须返回promise

最新更新