componentWillReceiveProps =(newProps)=> {
const _self = this;
//console.log('基本信息组件接受参数');
//console.log('newProps = ', newProps['basicInformationData']);
let videoLength = 0;
let videoSize = 0;
let distanceCreationTime = 0;
let tags = []
if( newProps['basicInformationData'] !== undefined) {
if ( newProps['basicInformationData']['distance_time'] !== undefined ) {
distanceCreationTime = newProps['basicInformationData']['distance_time']
}
if ( newProps['basicInformationData']['duration'] !== undefined ) {
videoLength = newProps['basicInformationData']['duration']
}
if ( newProps['basicInformationData']['size'] !== undefined ) {
videoSize = newProps['basicInformationData']['size']
}
if ( newProps['basicInformationData']['tags'] !== undefined ) {
tags = newProps['basicInformationData']['tags']
}
}
_self.setState({
tags: tags, // 任务所有名称
videoLength: videoLength,
videoSize: videoSize,
distanceCreationTime: distanceCreationTime
})
}
下面这段怎么优化?
_self.setState({
tags: tags, // 任务所有名称
videoLength: videoLength,
videoSize: videoSize,
distanceCreationTime: distanceCreationTime
})
这个if怎么优化
if( newProps['basicInformationData'] !== undefined) {
if ( newProps['basicInformationData']['distance_time'] !== undefined ) {
distanceCreationTime = newProps['basicInformationData']['distance_time']
}
if ( newProps['basicInformationData']['duration'] !== undefined ) {
videoLength = newProps['basicInformationData']['duration']
}
if ( newProps['basicInformationData']['size'] !== undefined ) {
videoSize = newProps['basicInformationData']['size']
}
if ( newProps['basicInformationData']['tags'] !== undefined ) {
tags = newProps['basicInformationData']['tags']
}
}