Bùi*_*hôi 5 javascript react-native redux-saga
每次我使用取与异步 等待着它的阻止了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;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
934 次 |
| 最近记录: |