鍍金池/ 問答/HTML/ 大家?guī)臀铱匆幌逻@個為什么報錯呢?

大家?guī)臀铱匆幌逻@個為什么報錯呢?

大家?guī)臀铱匆幌逻@個為什么報錯呢?

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}};
回答
編輯回答
莓森

從你貼的代碼上沒看到state.approveReducer是否定義了

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

如果這個函數(shù)里面的state.approveReducer是空的話,你直接用state.approveReducer.auditStateList是會報這個錯的

2018年7月12日 03:23
編輯回答
風(fēng)畔

將componentWillMount改為componentWillReceiveProps

componentWillMount函數(shù)沒有形參

2018年3月20日 12:26