大家帮我看一下这个为什么报错呢?
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
是否定义了如果这个函数里面的
state.approveReducer
是空的话,你直接用state.approveReducer.auditStateList
是会报这个错的