每次我使用获取 异步 等待它阻止了js线程,它的帧丢弃为1.这是我的代码:
export const apiCall = async (method, url, body) => {
const token = await getLocalToken();
const params = {
method: method.toUpperCase(),
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
}
};
if (body) {
params.body = JSON.stringify(body);
}
if (token) {
params.headers.Authorization = `Bearer ${token}`;
}
const start = Moment();
const res = await fetch(`${apiUrl}${url}`, params);
let json = res;
try {
json = await res.json();
} catch (e) {
console.tron.log(e);
}
return json;
}