0

我的 WIX 网站中有以下功能,它向外部 API 发出请求:

export function current_pull(page, per_page, filter_mode, view_id) {

 const url_request = URL + page + '&per_page=' + per_page + '&filtermode=' + filter_mode + '&view_id=' + view_id;

 return fetch(url_request, {        
    method: 'get',
    headers: {
            'X-AUTH-TOKEN': API_KEY,
            'X-SUBDOMAIN': SUBDOMAIN
        },
 }).then(function(response) {
    if (response.status >= 200 && response.status < 300) {
        console.log("current answered");
        var items = response.json();
        console.log(items);
    } else {
        console.log("there was an error" + response.statusText);
    }
 })
 .catch( (err) => {
    console.log(err);
 });
}

console.log(items);输出:

Promise {
_c: [],
_a: undefined,
_s: 0,
_d: false,
_v: undefined,
_h: 0,
_n: false }

如何获得实际的 API 响应

4

1 回答 1

1

response.json()也是Promise如此,在这种情况下,您需要按如下方式更改代码:

response.json().then(items => console.log(items))

您可以在此处查看更多文档:Body.json()

于 2018-03-05T09:34:53.707 回答