renderScene ={SceneMap({
'1':() => <FirstRoute {...this.state.data}/>,
'2':() => <SecondRoute {...this.state.data,...this.props.navigation}/>
这是完整的代码
render() {
if(!this.state.loading){
return (
<View
style={{
flex: 1,
}}>
<StatusBar
backgroundColor="mediumpurple"
barStyle="light-content"/>
<TabView
style={styles.container}
navigationState={this.state}
renderScene ={SceneMap({
'1':() => <FirstRoute {...this.state.data}/>,
'2':() => <SecondRoute {...this.state.data, ...this.props.navigation}/>,
})}
renderHeader={this._renderHeader}
onIndexChange={index => this.setState({ index })}
/>
</View>
);
}else{
return (
<View style={styles.loadingContainer}>
<ActivityIndicator size="large" color="#0000ff" />
</View>
);
}
}
}
答案 0 :(得分:0)
此{...a, ...b}
不是javascript表达式,因此会引发意外令牌错误。
您可以使用以下之一:
<SecondRoute {...{...this.state.data,...this.props.navigation}} />
const mergedObjects = {...this.state.data,...this.props.navigation}
<SecondRoute {...mergedObjects}/>
<SecondRoute {...this.state.data} {...this.props.navigation} />