加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

react typescript 子组件给父组件传值

发布时间:2020-12-15 20:14:37 所属栏目:百科 来源:网络整理
导读://父组件 import * as React from ‘react‘ import { Input } from ‘antd‘ const Search = Input.Search import "./index.less" import Child from "./compon/list" export default class ProjectList extends React.ComponentIProps{ constructor(props:

//父组件

import * as React from ‘react‘
import { Input } from ‘antd‘
const Search = Input.Search
import "./index.less"
import Child from "./compon/list"
export default class ProjectList extends React.Component<IProps>{
constructor(props: IProps) {
super(props)

}

handle = (val) => {  //val就是子组件传的值1
console.log(val)
// this.setState({
// mess:val
// })
}render(){
   
return (
<div>
 
  <Child  GETState= {this.handle.bind(this)} />
  </div>
)
}

}
//子组件
import * as React from ‘react‘
import { Row,Col } from ‘antd‘;
import "./list.less"

interface IProps {
msg?: any
MakeMoney?:any
GETState?: any //主要这段代码
}
interface IState {
lg?: any

}
export  default class List extends React.Component<IProps,IState> {  constructor(props: IProps) {    super(props)      }  state = {    lg: 6,a:68  }  toggle = () => {    console.log(‘f‘)      this.setState({        lg: 12      })  }  render(){    console.log(this.props.msg)   const { lg } = this.state;    return (      <div>        <button onClick={() => this.props.GETState(this.state.a)}>子组件</button>  )}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读