【问题标题】:Pass Array/Object as parameter in Axios React native在 Axios React native 中传递 Array/Object 作为参数
【发布时间】:2019-06-18 04:36:08
【问题描述】:

我想在 Axios 库中将 POST 请求中的参数传递为:

{
  params : 
  {
            email: email,
            password: password,
  }
}

我试过了:

axios.post(url, 
            { 
                params : {
                    email: 'a@aa.com',
                    password: 'Password!',
                    sign_in_type: '1',
                    fb_token: '',
                    google_token: ''
                }
            }, 
            {headers: headers}
        )

但是没有任何效果!如果您有任何想法,请提出建议。

谢谢!

【问题讨论】:

    标签: react-native post axios


    【解决方案1】:
     const getData = async () => {
            const params = {
              params: {
                  email: 'something@somelthing.com',
                  .....
              }
            };
        try {
            const { data } = await axios({
                method: 'post', 
                url: `your url`,
                data: params,
                headers: {
                 'token': token
               }
            });
         console.log(data);
        } catch(e) {
         console.log(e);
        }
     }
    

    【讨论】:

    • 在这我将如何得到回应?表示 .then 方法?
    • 在数据变量中,如果你想处理错误可以使用try和catch块,让我更新我的答案来告诉你更多
    • @Samad 还有一件事,实际上我是新手,所以.. 我需要对 getData 做些什么吗?并且日志中的数据排序是响应?
    • 我刚刚创建了一个名为 getData 的函数,您可以从某个地方调用它
    猜你喜欢
    • 2022-11-20
    • 2018-07-01
    • 2021-06-22
    • 2014-03-05
    • 2021-10-04
    • 1970-01-01
    • 2015-08-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多