react 中子组件调用父组件的方法
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 中子组件调用父组件的方法的更多相关文章
- React篇-子组件调用父组件方法,并传值
react 中子组件调用父组件的方法,通过props: 父组件: isNote(data){} <div className="tabC01"> <FTab ta ...
- Vue中子组件调用父组件的方法
Vue中子组件调用父组件的方法 相关Html: <!DOCTYPE html> <html lang="en"> <head> <meta ...
- Vue子组件调用父组件的方法
Vue子组件调用父组件的方法 Vue中子组件调用父组件的方法,这里有三种方法提供参考 第一种方法是直接在子组件中通过this.$parent.event来调用父组件的方法 父组件 <temp ...
- react typescript 子组件调用父组件
//父组件 import * as React from 'react'import { Input } from 'antd'const Search = Input.Searchimport &q ...
- vue 子组件调用父组件的方法
vue中 父子组件的通信: 子组件通过 props: { //子组件中写的. childMsg: { //字段名 type: Array,//类型 default: [0,0,0] //这样可以指定默 ...
- Vue 子组件调用父组件 $emit
<!DOCTYPE html><html> <head> <meta charset="utf-8"> ...
- vue 子组件调用父组件的函数
子组件调用父组件的函数,使用$emit(eventName,[...args]),触发当前实例上的事件.附加参数都会传给监听器回调. 子组件 <template> <div> ...
- 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 ...
随机推荐
- cookie——创建、获取、删除
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- tarjan算法(求强连通子块,缩点)
tarjan算法求图中的强连通子图的个数. #include<iostream> #include<stack> #include<queue> #include& ...
- Javascript - ExtJs - Toolbar - 工具栏
Toolbar组件 创建工具栏 Toolbar类是一种子组件,它不能独立存在,需要依附在其它组件上面.很多容器组件都具备tbar(顶部工具栏).bbar(底部工具栏)的配置,所以可以像下面那样使用它. ...
- oracle 修改数据文件路径
一.关库修改文件位置 1.连接到数据库 [oracle@linux]$ ./sqlplus /nolog SQL> conn / as sysdba 2. 查看数据文件位置 SQL> ...
- python基础-----变量和简单数据类型
初识变量 1.变量命名规则: a.字母 b.数字(不能开头) c.下划线 ps.硬性规定,命名必须是字母,数字,下划线,且不能以数字开头. 软性规则,以下划线分割 2.实例: a.写法: age_of ...
- python正则表达式获取代理IP网站上的IP地址
import urllib.request import re def open_url(url): req = urllib.request.Request(url) req.add_header( ...
- hadoop-1.2.1集群搭建
继续上一篇:http://www.cnblogs.com/CoolJayson/p/7430654.html 首先需要安装上台虚拟机, 分别为: master, salve1, slave2 1.复制 ...
- Java基础4-面向对象概述;super();this()
昨日内容回顾 java基本数据类型: byte : 一个字节,-128 ~ 127 = 256 short : 两个字节, -32768 ~ 32767 int : 四个字节, long : 八个字节 ...
- 【leetcode】557. Reverse Words in a String III
Algorithm [leetcode]557. Reverse Words in a String III https://leetcode.com/problems/reverse-words-i ...
- (转载)深度剖析 | 可微分学习的自适配归一化 (Switchable Normalization)
深度剖析 | 可微分学习的自适配归一化 (Switchable Normalization) 作者:罗平.任家敏.彭章琳 编写:吴凌云.张瑞茂.邵文琪.王新江 转自:知乎.原论文参考arXiv:180 ...