TypeError:无法读取未定义的属性'then'---我该如何解决?

我不确定为什么我的函数给我这个错误。在返回值的函数中,我确保所有级别上都有一个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});                  
            }             
        );
    }
 }
lindw1981 回答:TypeError:无法读取未定义的属性'then'---我该如何解决?

this.props.getDetails(Number)中的

componentDidMount被评估为undefined,因为getDetails中的mapDispatchToProps不会返回任何内容。

像这样更改:

function mapDispatchToProps(dispatch) {
    return {
        getDetails(Number) {
            return dispatch(getActions.getDetails(Number));
        }
    };
}
本文链接:https://www.f2er.com/2938857.html

大家都在问