当前位置: 首页 > Web前端 > JavaScript

Day37-100React事件传参方法

时间:2023-03-27 15:49:38 JavaScript

(1)需求最近在学习React,学习了React事件传参的方法以后记录一下。(二)介绍1.bind形式传递参数。绑定表单参数排在第一位。clickBtn=(params,event)=>{console.log('[event]>',params,event)this.setState({sum:params+1})}Click+12.箭头函数参数以箭头函数参数形式传递clickBtnCount=(event,params)=>{console.log('[clickBtnCount]>',event,params)this.setState({count:params+2})}this.clickBtnCount(e,this.state.count)}type="primary">点击+2(3)完成Demo/**@Author:ArdenZhao*@Date:2022-04-1315:48:04*@LastEditTime:2022-04-1316:23:15*@FilePath:/react-ts/src/components/react/6-enent-this.js*@Description:文件信息*/importReactfrom'react';import"antd/dist/antd.css";import{Button}from'antd';classSubComponentextendsReact.Component{//mountstageconstructor(props){super(props);this.state={name:'雅顿',sum:1,count:0,}}//bind的形式,第一个参数为参数值,第二个参数为事件clickBtn=(params,event)=>{console.log('[event]>',params,event)this.setState({sum:params+1})}clickBtnCount=(event,params)=>{console.log('[clickBtnCount]>',event,params)this.setState({count:params+2})}render(){return(<>

事件参数传递

1、绑定表单参数passing_counter:{this.state.sum}

Click+1

2.箭头函数参数传递_counter:{this.state.count

this.clickBtnCount(e,this.state.count)}type="primary">Click+2)}}functionReactParams(props){return(

学习,{props.name}

);}exportdefaultReactParams写在学习旅程的最后,经常偷懒《有想学技术需要监督的同学嘛~》https://mp.weixin.qq.com/s/Fy...有需要的朋友可以加我微信:learningisconnecting也可以关注我的公众号:国行聊成长(我会分享成长的方法)