按钮的标题属性必须是字符串 \- 反应原生

新手上路,请多包涵

在设备上运行时出现这样的错误“ 按钮的标题属性必须是字符串 - 反应原生

 import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
Button,
View
} from 'react-native';

export default class sample extends Component {

render() {
return (
    <Button
      style={{fontSize: 20, color: 'green'}}
      styleDisabled={{color: 'red'}}
      onPress={() => this._handlePress()}>
      title="Press Me"
    </Button>
);
}

_handlePress() {
  console.log('Pressed!');
}
}

AppRegistry.registerComponent('sample', () => sample);

原文由 Ravindhiran 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 204
1 个回答

我认为您太早关闭了 Button 标记。

 <Button
  style={{fontSize: 20, color: 'green'}}
  styleDisabled={{color: 'red'}}
  onPress={() => this._handlePress()}> // <-- closed tag here
  title="Press Me"
</Button>

只需在title属性后关闭标签

<Button
  style={{fontSize: 20, color: 'green'}}
  styleDisabled={{color: 'red'}}
  onPress={() => this._handlePress()}
  title="Press Me"
>
  Press Me
</Button>

原文由 Freeman Lambda 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题