react 自我小计

1、react中的方法调用,在onClick事件中不需要加小括号。

<button onClick={this.show}>方法的调用</button>  

 show(){
        console.log('按钮的onclick事件触发');
    }

2、react中使用this.setState,在onClick事件中不需要加小括号,但是在方法上要用箭头函数。下面这个例子也给出了回调函数的使用。

<button onClick={this.reState}>重新渲染</button>

 reState=()=>{            
        this.setState({
            Name:'Beautiful Girl!'
        },function(){console.log('问:this.setState在哪里使用箭头函数?回调函数中的state:'+this.state.Name)})
        console.log('重新reState的state值:'+this.state.Name);
    }

3、react中传递参数,在onClick事件中需要使用箭头函数,在方法上不需要箭头函数。

<button onClick={()=>this.passMsg('问:要触发传参在哪里使用箭头函数?')}>传递参数</button>

 passMsg(arg1){
            console.log(arg1);
    }

 

转载于:https://www.cnblogs.com/qingshanyici/p/10176814.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值