1.在父组件中定义方法,并绑定在子组件上

// 在子组件中调用父组件中的方法
import React,{Component} from 'react';
import Child from './child' class Parent extends Component{
constructor(props){
super(props);
this.fun=this.fun.bind(this);
}
fun(){
console.log('你调用了父组件的方法')
}
render(){
return (
<div>
<Child getFun={this.fun}></Child>
</div>
)
}
} export default Parent;

  

2.在子组件中通过this.props来调用父组件中的方法、

// 在子组件中调用父组件中的方法
import React,{Component} from 'react'; class Child extends Component{
constructor(props){
super(props);
console.log(this.props,'0000000000000000')
}
render(){
return(
<div>
child
<button onClick={()=>{console.log('你点击了按钮');this.props.getFun()}}>点击</button>
</div>
)
}
} export default Child;

  

react 中子组件调用父组件的方法的更多相关文章

  1. React篇-子组件调用父组件方法,并传值

    react 中子组件调用父组件的方法,通过props: 父组件: isNote(data){} <div className="tabC01"> <FTab ta ...

  2. Vue中子组件调用父组件的方法

    Vue中子组件调用父组件的方法 相关Html: <!DOCTYPE html> <html lang="en"> <head> <meta ...

  3. Vue子组件调用父组件的方法

    Vue子组件调用父组件的方法   Vue中子组件调用父组件的方法,这里有三种方法提供参考 第一种方法是直接在子组件中通过this.$parent.event来调用父组件的方法 父组件 <temp ...

  4. react typescript 子组件调用父组件

    //父组件 import * as React from 'react'import { Input } from 'antd'const Search = Input.Searchimport &q ...

  5. vue 子组件调用父组件的方法

    vue中 父子组件的通信: 子组件通过 props: { //子组件中写的. childMsg: { //字段名 type: Array,//类型 default: [0,0,0] //这样可以指定默 ...

  6. Vue 子组件调用父组件 $emit

    <!DOCTYPE html><html>    <head>        <meta charset="utf-8">      ...

  7. vue 子组件调用父组件的函数

    子组件调用父组件的函数,使用$emit(eventName,[...args]),触发当前实例上的事件.附加参数都会传给监听器回调. 子组件 <template> <div> ...

  8. react 子组件调用父组件方法

    import React from 'react'import '../page1/header.css'import { Table } from 'antd'import Child from ' ...

  9. react 父组件调用子组件方法、子组件调用父组件方法

    我们闲话不多说,直接上代码 // 父组件 import React, {Component} from 'react'; class Parents extends Component { const ...

随机推荐

  1. Unicode与Ansi互转

    BOOL CTool::AnsiToUnicode(const char *pSrc, CString &strResult) { #ifndef _UNICODE return FALSE; ...

  2. fastclick.js插件使用简单说明

    为什么存在延迟? 从点击屏幕上的元素到触发元素的 click 事件,移动浏览器会有大约 300 毫秒的等待时间.为什么这么设计呢? 因为它想看看你是不是要进行双击(double tap)操作.     ...

  3. 【CentOS】MySQL的安装

    版本信息:CentOS 7.2 64位 CentOS(Community Enterprise Operating System,中文意思是:社区企业操作系统)是Linux发行版之一,它是来自于Red ...

  4. Activemq -- Spring 整合

    转自: https://www.cnblogs.com/jaycekon/p/ActiveMq.html

  5. docker remote api 的安全隐患

    开启docker的api,首先要知道docker的守护进程daemon,在下认为daemon作为Client和service连接的一个桥梁,负责代替将client的请求传递给service端. 默认情 ...

  6. android动态设置组件LayoutParams

    开发中经常用到动态设置组件的LayoutParams,之前开发遇到的问题如下: LinearLayout.LayoutParams params = new LinearLayout.LayoutPa ...

  7. filter、map、sorted和reduce函数

    内置函数——filter.map和reduce filter filter()函数接收一个函数 f 和一个list,这个函数 f 的作用是对每个元素进行判断,返回 True或 False,filter ...

  8. 应用 XAF 开发移动手机应用

    应用 XAF 开发移动手机应用: 1. How to create a native mobile or lightweight web client UI based on the existing ...

  9. pymongo加索引以及查看索引例子

    # -*- coding: utf-8 -*- # @Time : 2018/12/28 10:01 AM # @Author : cxa import pymongo db_configs = { ...

  10. ansible笔记(12):handlers的用法

    ansible笔记():handlers的用法 这篇文章会介绍playbook中handlers的用法. 在开始介绍之前,我们先来描述一个工作场景: 当我们修改了某些程序的配置文件以后,有可能需要重启 ...