RN学习基础整理

2020-10-13 » iOS开发基础

https://www.runoob.com/react/react-event-handle.html

事件绑定

    render() {
        return(
            <Text style={styles.mybutton}
                       onPress={this.userConfirmed.bind(this)} >{this.state.data}</Text>
            // <Text style={styles.mybutton}
            //            onPress={(e) => this.userConfirmed()} >{this.state.data}</Text>
        );
    }

    userConfirmed () {
        this.setState({
            data: '已购买'
        });
    }
    
    
    <a href="https://reactjs.org" onClick={this.preventPop.bind(this,this.state.name)}>Click</a>
    
    preventPop(name, e){    //事件对象e要放在最后
    e.preventDefault();
    alert(name);
    }