React-native fetch使javascript阻塞

时间:2018-02-19 05:16:56

标签: 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;
}

0 个答案:

没有答案