繁体   English   中英

我想问一下这个错误 Unhandled Rejection (TypeError): Cannot destructure property `data` of 'undefined' or 'null'

[英]i wanted to ask about this error please Unhandled Rejection (TypeError): Cannot destructure property `data` of 'undefined' or 'null'

所以首先我在使用 redux 的身份验证中使用它,每次我尝试填写 email 和密码 forms 并单击登录它给我这个错误

未处理的拒绝 (TypeError):无法解构“未定义”或“空”的属性data

这是我的代码:

import {AUTH_ATTEMPTING, AUTH_SUCCESS, AUTH_FAILED } from'./types';
import axios from 'axios';

const token_name= 'vendo_app_token';
export const login = (request_data) =>{
    return async dispatch =>{
        dispatch ({type: AUTH_ATTEMPTING})
        try{
            const {data: {token}} = await axios.post('http://localhost:5000/api/V1/login', request_data);
            dispatch(success(token) );
        }catch(e){
            const {response: {data}} = e;
            dispatch(error(data.error));                                  
        }
    };
};

这是我用来连接到主页的路径

if(isAuth===true){
    this.props.history.push('/register');
}

您解构data的唯一地方是在错误处理程序中,您试图在其中解构以最终获得e.response.data 您收到的错误消息表明抛出的错误没有response属性。

尝试:

} catch(e) {
  if ( ! e.response ) {
    console.error( 'Error without response:', e );
  } else {
    const { response : { data } } = e;
    dispatch( error( data.error ) );
  }
}

嘿,杰森,好吧,我又遇到了一个错误,让我告诉你

类型错误:无法读取未定义的属性“推送”

36 |    );
  37 |    }
  38 |    if(isAuth){
> 39 |      this.props.history.push('/');
     | ^  40 |    }
  41 |  }
  42 | 

这个错误也是:

  12 |              console.error( 'Error without response:', e );
  13 |            } else {
  14 |              const { response : { data } } = e;
> 15 |              dispatch( error( data.error ) );
     | ^  16 |            }
  17 |          }
  18 | 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM