【问题标题】:React Native JSX error: elements must be wrapped in an enclosing tagReact Native JSX 错误:元素必须包含在封闭标记中
【发布时间】:2018-09-29 22:08:58
【问题描述】:

我不知道为什么我的模拟器会出现以下错误:

Adjacent JSX elements must be wrapped in an enclosing tag

代码:

render() {
    return (
    <View>
    <TextInput
        underlineColorAndroid={'transparent'}
        style={styles.searchInput}
        placeholder='Enter Part Name(s)'
    />

    <TextInput
        underlineColorAndroid={'transparent'}
        style={styles.searchInput}
        placeholder='Enter Basic Number(s)'
    />

    <Button
        onPress={this._onBackPressed}
        title='Go'
    </Button>

    </View>
    );
}

【问题讨论】:

    标签: react-native jsx


    【解决方案1】:

    缺少 View-tag 的开头(节点的开头)。该按钮也缺少“>”

    render() (
      <View> // this one were missing
        <TextInput
          underlineColorAndroid={'transparent'}
          style={styles.searchInput}
          placeholder='Enter Basic Number(s)'
        />
    
        <Button
          onPress={this._onBackPressed}
          title='Go'
        > // this one were missing
        </Button>
    
     </View>
    )
    

    您可以在 JSX 参考页面阅读更多内容:https://reactjs.org/docs/jsx-in-depth.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-30
      • 2017-08-30
      • 2019-06-14
      • 2019-09-29
      • 2019-11-06
      • 2019-01-12
      • 2020-06-14
      相关资源
      最近更新 更多