【问题标题】:Can we use axios post inside axios post?我们可以在 axios post 中使用 axios post 吗?
【发布时间】:2019-11-13 06:03:09
【问题描述】:

我需要从 api 获取会话 ID,并将其用作 Axios POST 输入的一部分以获取用户信息。但是,尽管我在代码中找不到任何错误,但我总是收到会话过期错误。请帮帮我!

   data() {
        return {
            customer: {
                data:{
                    method: "customer_login",
                    email: "vishal@magemad.com",
                    password: "admin123",
                    session_id: ""
                }
            }
        };

登录(){

            var api = 'http://159.203.179.154/sports-web/webservices/api2.php';
            var admin = {
                    data: {
                        method: "admin_login",
                        key: "admin123",
                        user: "admin"  
                    }                  
            };
            let  axiosConfig = {
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded',
                        "Access-Control-Allow-Origin": "*",
                    }
            }; 

            Axios.post(api, admin, axiosConfig)
                .then((res) => {
                    const id = res.data.data.session_id.slice(2,-2);
                    this.customer.data.session_id = id;

                    Axios.post(api, this.customer)
                        .then((res) => {
                            console.log(JSON.stringify(this.customer.data));
                            //console.log(res);
                            alert(JSON.stringify(res));
                        })
                        .catch((err) => {
                            console.log("AXIOS ERROR:", err);
                        });
                    //alert(JSON.stringify(this.customer));
                })
                .catch((err) => {
                    console.log("AXIOS ERROR:", err);
                });

【问题讨论】:

  • 我不知道您的后端是如何工作的,但是您在以管理员身份登录后尝试以客户身份登录。前端代码没有问题,但您可能正在做一些您不应该做的事情。

标签: php vue.js axios nativescript-vue


【解决方案1】:

我找到了答案。原来我不需要对会话 id 进行切片。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-03
    • 1970-01-01
    • 2019-02-01
    • 2019-01-04
    • 2022-01-11
    • 2021-09-17
    • 2019-08-29
    • 2020-05-17
    相关资源
    最近更新 更多