
react传参的方法:
1、使用bind
import React, { Component } from 'react' class App extends Component{ constructor(props){ super(props) this.state = { test:"哈哈" } } render(){ return( <div> <button onClick={this.getValue.bind(this,this.state.test)}>确定</button> </div> ) } getValue(val){ console.log(val); } } export default App ;
2、使用箭头函数
import React, { Component } from 'react' class App extends Component { constructor(props) { super(props) this.state = { test: "哈哈" } } render() { return ( <div> <button onClick={() => this.getVal(this.state.test)}>确定</button> </div> ) } getVal = (val) => { console.log(val); } } export default App;
相关学习推荐:react视频教程
以上就是react怎样传参的详细内容,更多请关注易知道|edz.cc其它相关文章!