Api调用不返回数组中的所有对象

时间:2018-04-18 20:59:46

标签: javascript json react-native

我正在调用此API https://reqres.in/api/users?page=1,我找不到数据属性中的所有三个对象。我只能看到第一个对象。

这是我使用的代码

        categoryApi.getOne(1).then(response => {
            if (response.data) {
                console.log('categories: ', response.data.data);
            }
        });

这就是回应:

Object {
 "avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/calebogden/128.jpg",
   "first_name": "George",
   "id": 1,
   "last_name": "Bluth",
 }

和axios调用函数如下所示:

getOne: id => {
        return axios.get('users?page=1', {
            params: {
                id: id
            }
        }).then(function (response) {
            return response;
        }).catch(function (error) {
            if (error.response) {
                // The request was made and the server responded with a status code
                return error;
            } else if (error.request) {
                // The request was made but no response was received
                return error.request;
            } else {
                // Something happened in setting up the request that triggered an Error
                return error.message;
            }
        });
    },

知道为什么它只获取第一个对象而不是所有三个对象?

1 个答案:

答案 0 :(得分:2)

因为您还在

中传递了id
params: {id: id}.

传递params,或传递空params,这就是全部。