[英]Common service file for reactJs
我想在 reactJs 中創建一個用於調用外部 api 的通用服務文件結構。 任何人都可以請建議並提供一些示例演示代碼嗎?
export async function GetAllAuthorizationElements() {
let response = null;
await fetch(baseUrl + "/yourroute", {
headers: defaultHeader
}).then((response) => response.json()).then(data => response = data);
if (!IsAuthorized(response)) {
alert("Unauthorized")
return 403;
}
return response;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.