博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
react typescript 父组件调用子组件
阅读量:4589 次
发布时间:2019-06-09

本文共 1171 字,大约阅读时间需要 3 分钟。

//父组件 import * as React from 'react' import { Input } from 'antd' const Search = Input.Search import "./index.less" import Child from "./compon/list"
interface IProps {
MakeMoney?: () => void } export default class ProjectList extends React.Component
{
constructor(props: IProps) {
super(props) }   
child: any = {}  //主要加这个 onRef = (ref) => {
this.child = ref } // 调用组件进行通信 getDS = () => {
this.child.toggle() }
render(){
return (   
    
    
   ) }
} //子组件
import * as React from 'react' import { Row, Col } from 'antd'; import "./list.less"
interface IProps {
msg?: any MakeMoney?:any //ref?:any } interface IState {
lg?: any }export default class List extends React.Component
constructor(props: IProps) {
super(props)   }   state = {
lg: 6 } toggle = () => {//父组件要调用的方法 console.log('f') this.setState({
lg: 12 }) } StudyMakeMoney=()=>{ // 调用父组件方法 this.props.MakeMoney(); } render(){
const { lg } = this.state; return (
  
  ) }

转载于:https://www.cnblogs.com/whlBooK/p/10811792.html

你可能感兴趣的文章
使用 MongoDB shell访问MongoDB
查看>>
MongoDB简介
查看>>
MongoDB 创建数据库
查看>>
MongoDB概念解析
查看>>
MongoDB Java
查看>>
MongoDB 插入文档
查看>>
UMP系统架构
查看>>
键值数据库
查看>>
UMP系统功能 容灾
查看>>
UMP系统功能 读写分离
查看>>
UMP系统功能 分库分表
查看>>
UMP系统功能 资源管理
查看>>
UMP系统功能 资源调度
查看>>
UMP系统功能 资源隔离
查看>>
UMP系统功能 数据安全
查看>>
Amazon AWS
查看>>
Amazon AWS EC2存储
查看>>
Amazon S3和EBS的区别
查看>>
AWS云管理平台
查看>>
NoSQL SimpleDB
查看>>