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 ...
随机推荐
- openwrt package 依赖关系
参考链接: https://blog.csdn.net/zxygww/article/details/49181065
- C++ 类使用多线程技术
参考文章 : http://blog.csdn.net/jmh1996/article/details/72235232 成员函数作为线程函数, 要将成员函数定义为静态的 C++ 静态成员函数调用非 ...
- struts基础3-把数据写入页面
一.OGNL(Object-Groph Navigation Language) 是一种强大的表达式语言,可以存取对象的任意属性,调用对象的方法,遍历整个对象的结构图,实现字段类型转化等功能. 1)与 ...
- AspectJ使用的遇到的坑
1.导入包,但不是使用,会导致R文件错误 apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply pl ...
- F - Change FZU - 2277 (DFS序+线段树)
题目链接: F - Change FZU - 2277 题目大意: 题意: 给定一棵根为1, n个结点的树. 有q个操作,有两种不同的操作 (1) 1 v k x : a[v] += x, a[v ' ...
- Centos7 nginx提示错误 Access denied.
SELinux will cause this error on CentOS/RHEL 7+ by default :( CentOS/RHEL 7+ 系统默认会因为SELinux出现这个报错 To ...
- 待解决new int(i*j)
这里的确应该用new int [i*j] 来申请一片空间,但new int(i)的含义就像是给p指针指向的内容赋值了,相当于只申请了一个4个字节. 问题是,为什么后面b不能输出结果呢? #includ ...
- Git学习笔记02-创建版本库
版本库就是一个目录,这个目录里面的所有文件都会被Git管理,每个文件的修改,删除都能追踪.以便在某个时刻追踪历史记录,或者还原 路径切换,查看文件命令和linux差不多,cd 文件路径 ls查看路径 ...
- js判断空字符串、null、undefined、空格、中文空格
代码 function isEmpty(obj) { if (obj === null) return true; if (typeof obj === 'undefined') { return t ...
- 带你玩转Visual Studio——带你了解VC++各种类型的工程
原文地址:http://blog.csdn.net/luoweifu/article/details/48816605 上一篇文章带你玩转Visual Studio——带你新建一个工程一文中提到新建一 ...