大家帮我看一下这个为什么报错呢?

大家帮我看一下这个为什么报错呢?

import React, { Component, Fragment } from 'react';
import {bindActionCreators} from 'redux';
import {getApplyAudit} from './actions/approve-actions';
import {connect} from "react-redux";
import {Steps} from 'antd';
import moment from 'moment';
const Step = Steps.Step;

class ApproveSituation extends Component {
    constructor() {
        super();
        this.state={
            status: '',

        };
    }

    componentWillMount(record) {
        const {busiType} = this.props;
        let busi_type = busiType?busiType:'';
        this.props.getApplyAudit(record.id,busi_type=='container'?'container':'apply');

    }

    componentDidMount() {

    }
    checkStatus = (record) => {
        switch (record) {
            case '1':
                return 'wait';
            case '2':
                return 'process';
            case '3':
                return 'finish';
            case '4':
                return 'error';
            default: return null;
        }
    }

    getStatus(data){
        let status = [];
        if(data){
            for(let i = 1;i < data.length;i++){
                if(data[i].state != 3){
                    status.push(i);
                    status.push(data[i].state);
                    return status;
                }
            }
        }
    }

    render(){
        const {auditStateList} = this.props;
        console.log(auditStateList);
        const state = this.getStatus(auditStateList ? auditStateList.result ? auditStateList.result : [] : []);
        console.log('state:',state)
        const dataSource = auditStateList ? (auditStateList.result && Array.isArray(auditStateList.result))?
            auditStateList.result.map((item)=>
                <Step key={item.id} value={item.state} title={item.name}
                      description={<div style={{ display: 'flex', justifyContent: 'center' }}>
                          {item.time ? moment(item.time).format('YYYY/MM/DD'):'待处理'}</div>}/>) :[]:[];

        return (
            <Steps progressDot current={state ? state[0] ? state[0] : null : null}
                   status={this.checkStatus(state ? state[1] ? state[1] : null : null)}>
                {dataSource}
            </Steps>

        )
    }

}
function mapStateToProps(state) {
    return {
        auditRuleList:state.auditStateList
    }
}

function mapDispatchToProps(dispatch){
    return{
        getApplyAudit : bindActionCreators(getApplyAudit, dispatch),

    }
}
export default connect(mapDispatchToProps,mapStateToProps)(ApproveSituation);

图片描述
图片描述

//action文件
export function getApplyAudit(id,type,state) {
    const path='/auditing/getApplyAuditInfo';
    return{
    type:"APPLY_AUDIT_INFO",
        payload: {
            promise: api.get(path, {
                params:{
                    id,
                    type,
                    state
                }
            })
        }
    }
}
//reducer文件
case 'APPLY_AUDIT_INFO_PENDING':
    return {...state,auditStateList:{loading:true}};
case 'APPLY_AUDIT_INFO_SUCCESS':
    return {...state,auditStateList:{result:action.payload, loading:false}};
case 'APPLY_AUDIT_INFO_ERROR':
    return {...state,auditStateList:{loading:false}};
阅读 1.7k
2 个回答

从你贴的代码上没看到state.approveReducer是否定义了

function mapStateToProps(state) {
    return {
        auditRuleList:state.approveReducer.auditStateList
    }
}

如果这个函数里面的state.approveReducer是空的话,你直接用state.approveReducer.auditStateList是会报这个错的

将componentWillMount改为componentWillReceiveProps

componentWillMount函数没有形参

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题