TypeError: Cannot read property 'then' of undefined --- How do I resolve this?

TypeError: Cannot read property 'then' of undefined --- How do I resolve this?

我不确定为什么我的函数会给我这个错误。在函数 returning 值中,我确保在所有级别上都有一个 return 语句。关于为什么会发生此错误,我可以有第二个意见吗?服务 return 完美地提供了数据,但是前端没有从我的操作中看到 return。

我尝试了其他具有相同标题的解决方案,希望这不是重复的

前端:

componentDidMount() {       
    const { item } = this.props;
    this.props.getDetails(Number)
        .then((res) => {               
            this.setState({
                data: res.response.response.Results
            })
        });  
}

映射:

function mapDispatchToProps(dispatch) {
    return {
        getDetails(Number) {
            dispatch(getActions.getDetails(Number));
        }
    };
}

函数检索:

function getDetails(Number) { 
   return (dispatch) => {
       dispatch({ type: policyConstants.ITEM_GETDETAIL_REQUEST });
    return Service.getDetails(Number)
        .then(
            response => {                   
                dispatch({ type: Constants.ITEM_GETDETAIL_SUCCESS });
                var pDetails = response.response.Results;
                return { pDetails };
            },
            error => {
                dispatch({ type: policyConstants.POLICY_GETDETAIL_FAILURE, error});                  
            }             
        );
    }
 }

this.props.getDetails(Number) 在您的 componentDidMount 中被评估为 undefined 因为 getDetails 在您的 mapDispatchToProps returns 中什么都没有。

改成这样:

function mapDispatchToProps(dispatch) {
    return {
        getDetails(Number) {
            return dispatch(getActions.getDetails(Number));
        }
    };
}