热门:华为支持参数分辨率解决方法控制属性启动升级错误平台推荐步骤模式查询运行空间文件夹鼠标图标重启激活联想检查状态应用程序

react怎样传参

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其它相关文章!

推荐阅读