react typescript 子组件调用父组件
//父组件
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<IProps>{
constructor(props: IProps) {
super(props)
}
MakeMoney(){ //子组件调用父组件的方法
alert("我在学习react!");
}
render(){
return (
<div>
<div className="Input_box">
<div style={{ marginBottom: 16 }}>
<Search
placeholder="搜索"
onSearch={value => console.log(value)}
onChange={this.Inpchange}
enterButton
/>
<button>点击切换</button>
</div>
</div>
<Child MakeMoney={this.MakeMoney}/>//子组件
</div>
)
}
}
//子组件
import * as React from 'react'
import { Row, Col } from 'antd';
import "./list.less"
interface IProps {
msg?: any
MakeMoney?:any //获取暴露的方法
}
interface IState {
lg?: any
}
export default class List extends React.Component<IProps, IState> {
constructor(props: IProps) {
super(props)
}
StudyMakeMoney=()=>{ // 调用父组件方法
this.props.MakeMoney();
}
render(){
const { lg } = this.state;
return (
<div>
<button onClick={this.StudyMakeMoney}>子组件</button>
</div>
}
react typescript 子组件调用父组件的更多相关文章
- React篇-子组件调用父组件方法,并传值
react 中子组件调用父组件的方法,通过props: 父组件: isNote(data){} <div className="tabC01"> <FTab ta ...
- vue 子组件调用父组件的方法
vue中 父子组件的通信: 子组件通过 props: { //子组件中写的. childMsg: { //字段名 type: Array,//类型 default: [0,0,0] //这样可以指定默 ...
- Vue子组件调用父组件的方法
Vue子组件调用父组件的方法 Vue中子组件调用父组件的方法,这里有三种方法提供参考 第一种方法是直接在子组件中通过this.$parent.event来调用父组件的方法 父组件 <temp ...
- Vue 子组件调用父组件 $emit
<!DOCTYPE html><html> <head> <meta charset="utf-8"> ...
- vue 子组件调用父组件的函数
子组件调用父组件的函数,使用$emit(eventName,[...args]),触发当前实例上的事件.附加参数都会传给监听器回调. 子组件 <template> <div> ...
- Vue中子组件调用父组件的方法
Vue中子组件调用父组件的方法 相关Html: <!DOCTYPE html> <html lang="en"> <head> <meta ...
- react 子组件调用父组件方法
import React from 'react'import '../page1/header.css'import { Table } from 'antd'import Child from ' ...
- react 父组件调用子组件方法、子组件调用父组件方法
我们闲话不多说,直接上代码 // 父组件 import React, {Component} from 'react'; class Parents extends Component { const ...
- react 中子组件调用父组件的方法
1.在父组件中定义方法,并绑定在子组件上 // 在子组件中调用父组件中的方法 import React,{Component} from 'react'; import Child from './c ...
随机推荐
- Linux下C++访问MySQL数据库
由于想要开始了解并学习用LAMP进行web开发,所以昨晚我在Fedora上安装了MySQL,学习了MySQL的几个常用命令.想着在学习进行web开发(PHP访问数据库)之前,先用我熟悉的C++连接数据 ...
- ES 2016+
ES2016(ES7)新增: Array.prototype.includes Exponentiation Operator 求冥运算 ES2017 (ES8)新增: ECMAScript® 201 ...
- poj2011
Shortest Prefixes Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 17608 Accepted: 765 ...
- Razor项目所感(上)
简单的说下我的Razor四旋翼飞行器项目,还没做完,要暂时搁一搁,就先总结一下. 此项目基于Raspberry Pi上的linux平台进行开发,现仍在开发中.项目地址:https://github.c ...
- ALSA声卡驱动中的DAPM详解之三:如何定义各种widget
上一节中,介绍了DAPM框架中几个重要的数据结构:snd_soc_dapm_widget,snd_soc_dapm_path,snd_soc_dapm_route.其中snd_soc_dapm_pat ...
- P5058 [ZJOI2004]嗅探器 tarjan割点
这个题是tarjan裸题.最后bfs暴力找联通块就行.(一开始完全写错了竟然得了70分,题意都理解反了...这数据强度...) 题干: 题目描述 某军搞信息对抗实战演习,红军成功地侵入了蓝军的内部网络 ...
- 开源矿工README
点击加入 NTMiner官方QQ群: 863725136 开源矿工内置的所有内核均为原版,开源矿工永远不会额外增加矿工支出: 开源矿工永远开源: 开源矿工永远不会去破解国人开发的内核: 下载地址 阿里 ...
- .net 必看书籍2
一.入门 1.<HTML与CSS入门经典(第7版) >HTML入门 点评:html语言的入门,由于html极其简单所以同类其他书也可代替,本书并非经典,本书摆在这里纯属占位!你可以用其他书 ...
- Eclipse设置空格代替tab
1.点击 window->preference-,依次选择 General->Editors->Text Editors,选中右侧的 insert space for tabs;如下 ...
- Vue电商SKU组合算法问题
前段时间,公司要做“添加商品”业务模块,这也算是电商业务里面的一个难点了. 令我印象最深的不是什么“组合商品”.“关联商品”.“关联单品”,而是商品SKU的组合问题. 这个问题特别有意思,当时虽然大体 ...