所以我發出這樣的 POST 請求:
async createVisit(patientId: string, visitorId: string) {
const userJWT = jwt.sign(
{
_id: visit,
refreshCount: 0
},
this.localConfig.spirit.jwtSecret
)
const visitURL = this.localConfig.spirit.url
let response = await fetch(visitURL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer' userJWT
},
body: JSON.stringify(visit)
});
if (response.ok) {
let result = await response.json();
}
}
所以我需要回傳幾個屬性result以及一個新物件,以便在另一個類的方法中訪問。
uj5u.com熱心網友回復:
您只能從函式中回傳 1 個東西,但是如果您確實需要回傳 2 個東西,則可以將它們組合在一個陣列中
return [coupleOfPropertiesFromResult, newObject];
您也可以使用物件。
...
let result = await response.json();
return {
prop: result.prop,
another: result.another,
yetanother: 42
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/330844.html
標籤:javascript 打字稿
