0
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>
    );
  }
 }
}
4

1 回答 1

0

{...a, ...b}不是 javascript 表达式,因此,它会抛出Unexpected Token错误。

您可以使用以下方法之一:

  • <SecondRoute {...{...this.state.data,...this.props.navigation}} />
  • const mergedObjects = {...this.state.data,...this.props.navigation}

    <SecondRoute {...mergedObjects}/>

  • <SecondRoute {...this.state.data} {...this.props.navigation} />

于 2018-08-10T21:37:41.267 回答