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 ...
随机推荐
- 【Git】Git常用命令
git remote -v : 查看远程仓库地址
- 模拟post表单提交参数
Content-Type: application/x-www-form-urlencoded;charset=utf-8
- Struts2 REST 插件 XStream 远程代码执行漏洞 S2-052 复现过程
v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VM ...
- 解码base64加密的图片并打印到前台
经过base64加密的图片对象是一串字符串,我们解码后可通过流将其打印出来: utils类: package com.aebiz.app.web.modules.controllers.open.ap ...
- Spring boot+Thymeleaf+easyui集成:js创建组件页面报错
开发工具:Ideal 使用场景:Demo 前提: 环境:Spring boot +Thymeleaf+easyui 引入thymeleaf模板引擎 <html lang=" ...
- map中的count方法
map.count(Key)返回值为1或者0,1返回存在,0返回不存在,返回的是布尔类型的值,因为在map类型中所有的数据的Key值都是不同的,所以被count的数要么存在1次,要么不存在
- python,类和对象(二),self 、__init__(self,param[,param...])、__private(私有变量)
当我们在类中定义方法的时候,总会看到会第一个参数总是self,是的这个是python的一个语法,他相当于这个对象的指针. class Dog(): def setName(self,name): se ...
- yum install mariadb安装数据库开启不了
centos7内置的MySQL镜像已经放弃Oracle公司的MySQL,改用MySQL的分支数据库mariaDB,使用以下安装mariadb: yum install mariadb 然后使用命令sy ...
- k64 datasheet学习笔记45---10/100-Mbps Ethernet MAC(ENET)之功能描述
1.前言 本文是对K64 datasheet 之ENET部分的功能描述,将对每个部分进行详细说明 2.Ethernet MAC frame formats MAC帧组成格式 (1)7字节前导码:如按最 ...
- Mysql安装与配置调优
一.安装apt-get install mysql-server 需要设置账号密码 apt-get isntall mysql-client apt-get libmysqlclient-dev2.s ...