在 react-native android 应用程序中使用 axios 传递参数

在 react-native android 应用程序中使用 axios 传递参数

问题描述:

我需要在 react-native 中使用 AXIOS 传递一些参数,但不知道我应该如何使用 AXIOS 传递参数.

I require to pass some parameters with AXIOS in react-native but don't know how should I pass parameters with AXIOS.

我发现这篇文章很有用,但它不能完全满足我的问题.我需要传递以下参数以从 API 获取所有项目:

I found this post useful but its not fully satisfy my issue. I need to pass below parameters to fetch all items from API:

PHP 中的工作示例:

Working example in PHP:

$url = 'https://APISITE.net/api/Stock/GetStockItems?keyWord=6666777788889&locationId=""&entriesPerPage=10000&pageNumber=1&excludeCompposites=true';

$url = 'https://APISITE.net/api/Stock/GetStockItems?keyWord=6666777788889&locationId=""&entriesPerPage=10000&pageNumber=1&excludeComposites=true';

它在 PHP TEST 文件中运行良好,我只需要传递 keyword 值,即 6666777788889 即可获取数据.

Its working well in PHP TEST file and i only need to pass keyword value ie 6666777788889 to get data.

我不知道如何在 AXIOS 中传递这些值.请指导.

I dont know how to pass these values in AXIOS. Please guide.

需要在axios请求的config中指定params.

You need to specify params in the config of axios request.

axios.get('https://APISITE.net/api/Stock/GetStockItems', {
    params: {
        keyWord: 666677788899,
        locationId: 2,
        entriesPerPage: 100000,
        pageNumber: 1,
        excludeComposites: true,
        //add other params
    }
})

您可以查看 axios 的 github Readme 页面以供参考.

You can check axios's github Readme page for reference.