首页 > 解决方案 > 导航在 React Native 中的 axios 调用中不起作用

问题描述

我正在使用axiosReact Native 中的发布请求来执行登录用户功能。我已成功收到回复,但登录后我无法导航到主屏幕。这是我的代码。

axios.post('/wp-json/api/v1/user/do_login', {
        username: username,
        password: password
          })
          .then(function (response) {
              console.log(JSON.stringify(response.data.type));
              if(response.data.type == "success"){
                alert("Login Successfully");
                this.props.navigation.navigate("home");
              }else if(response.data.type == "error"){
                alert("Incorrect Detail");
              }


          })
          .catch(function (error) {
            console.log( JSON.stringify(response));
          });

在上面的代码中,我成功地得到了响应,但没有得到下一个屏幕。这是我正在导航到下一个屏幕..

this.props.navigation.navigate("home");

标签: reactjsreact-nativeaxios

解决方案


推荐阅读