函数的访问状态

时间:2018-09-22 18:58:11

标签: react-native state func

我正试图提醒this.state.name,但不幸的是,它显示无法读取属性名称错误

export default class SignUp extends Component {
  constructor(props) {
    super(props);
    this.state = {
    Pro: [],
    name:'g',
    phone:'',
    pass:'',

    }}

registerUser(){

alert(this.state.name)}

render(){
return(
<TouchableOpacity onPress={this.registerUser} style={styles.buttonContainer}
      onPress={this.registerUser}>})}

1 个答案:

答案 0 :(得分:0)

执行此操作:

registerUser =()=>{
alert(this.state.name)}

<TouchableOpacity>中的

onPress={()=>{this.registerUser()}}

它将起作用!