我正在尝试通过代码解决问题,并且不明白为什么它不起作用。
功能:
export const monthlyKpiActions_disp = (threeMonthsBefore, currentDate) => {
console.log('kpppppppppppppppi')
return monthlyKpiActions.fetch({
filter: {
objectId,
interval: threeMonthsBefore + '/' + currentDate,
names: [
'ecostats_fuelusagetotal',
'ecostats_fuelrefmileage',
'ecostats_co2emission',
'tripstats_mileage',
'tripstats_drivingtime',
'optidrive_indicator_8'
].join(',')
},
forceUpdate: true,
resetState: false
})
}
redux
function mapDispatchToProps(dispatch) {
return {
monthlyKpiActions_func: (threeMonthsBefore, currentDate) => dispatch(monthlyKpiActions_disp(threeMonthsBefore, currentDate)),
}
}
调用函数
const currentDate = moment.utc().add(1, 'months').format(dateFormat)
const threeMonthsBefore = moment.utc().subtract(3, 'months').format(dateFormat)
{ () => this.props.monthlyKpiActions_func(threeMonthsBefore, currentDate) }
问题是从不进入功能,有什么建议吗?
答案 0 :(得分:2)
那是因为您永远不会调用该行,
{ () => this.props.monthlyKpiActions_func(threeMonthsBefore, currentDate) }
使用匿名函数创建一个块范围,该函数在内部调用您的操作,但从未调用(在这种情况下也没有任何意义)。
只需执行以下操作:
this.props.monthlyKpiActions_func(threeMonthsBefore, currentDate)