import React, { Component } from 'react';
export default class App extends Component {
state = {
count:1
}
addM(m,event) {
console.log(event);
this.setState({count:this.state.count + m})
}
add (params1,params2,event) { // event是最后一个参数
this.setState({count:this.state.count + params1 + params2})
}
render() {
return (
<>
<div>count:{ this.state.count}</div>
{/* 1.react事件传递参数1:使用箭头函数包裹调用参数的函数 */}
<button onClick={(event) => {
const m = 100
this.addM(m,event)
}}>加m</button>
{/* 2.react事件传递参数2 */}
<button onClick={this.add.bind(this,1000,100)}>加</button>
</>
);
}
}
React两种传递参数的方式
最新推荐文章于 2025-02-10 00:27:26 发布