zoukankan      html  css  js  c++  java
  • react typescript 子组件给父组件传值

    //父组件

    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)} /> // 这种tslint git提交报bind错误
      <Child  GETState= {(val)=>this.handle(val)} />
      </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>
      )
    }
  • 相关阅读:
    哈密顿绕行世界问题 (dfs)
    山东省第八届ACM大学生程序设计竞赛
    HDU
    HDU
    hdu 1241(DFS/BFS)
    centos7 df 命令卡死
    hosts文件修改之后立刻刷新
    shell脚本打印日期时间
    CentOS6设置php-fpm开机自启动
    Word中怎么设置忽略拼写和语法检查提醒
  • 原文地址:https://www.cnblogs.com/whlBooK/p/10812219.html
Copyright © 2011-2022 走看看