在设备上运行时出现错误,如“按钮的标题支柱必须是字符串 - 反应原生”
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);
答案 0 :(得分:9)
我认为你太早关闭了Button标签。
<Button
style={{fontSize: 20, color: 'green'}}
styleDisabled={{color: 'red'}}
onPress={() => this._handlePress()}> // <-- closed tag here
title="Press Me"
</Button>
只需在标题属性
之后关闭标记即可<Button
style={{fontSize: 20, color: 'green'}}
styleDisabled={{color: 'red'}}
onPress={() => this._handlePress()}
title="Press Me"
>
Press Me
</Button>
答案 1 :(得分:1)
按钮名称应使用标题关键字
编写示例:
<Button
style={{fontSize: 20, color: 'green'}}
styleDisabled={{color: 'red'}}
onPress={() => this._handlePress()}
title="Press Me"
>
</Button>
按钮标签中的title =“按我”
答案 2 :(得分:0)
实际上,就我而言,我缺少了“标题” 支柱。这就是为什么它显示错误。当我添加“标题” 道具时,该错误消失了。就是这样。