react 子组件调用父组件方法
import React from 'react'
import '../page1/header.css'
import { Table } from 'antd'
import Child from './child'//引入的子组件
export default class Header extends React.Component{
constructor(){
super()
}
}
MakeMoney(){
alert("我在学习react!");
}
render(){
return (<div>
<Child MakeMoney={this.MakeMoney} />
</div>
}
//子组件
import React from 'react'
export default class Header extends React.Component{
constructor(props){
super(props)
}
StudyMakeMoney=()=>{ // 调用父组件方法
this.props.MakeMoney();
}
render(){
console.log(this.props.msg)
return (
<div className="header">
<button onClick={this.StudyMakeMoney}>调用父组件中的方法</button> //点击按钮通过StudyMakeMoney方法中this.props.MakeMoney();
</div>
)
}
}
react 子组件调用父组件方法的更多相关文章
- React篇-子组件调用父组件方法,并传值
react 中子组件调用父组件的方法,通过props: 父组件: isNote(data){} <div className="tabC01"> <FTab ta ...
- 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子组件调用父组件的方法
Vue子组件调用父组件的方法 Vue中子组件调用父组件的方法,这里有三种方法提供参考 第一种方法是直接在子组件中通过this.$parent.event来调用父组件的方法 父组件 <temp ...
- Vue中子组件调用父组件的方法
Vue中子组件调用父组件的方法 相关Html: <!DOCTYPE html> <html lang="en"> <head> <meta ...
- Vue 子组件调用父组件 $emit
<!DOCTYPE html><html> <head> <meta charset="utf-8"> ...
- vue 子组件调用父组件的函数
子组件调用父组件的函数,使用$emit(eventName,[...args]),触发当前实例上的事件.附加参数都会传给监听器回调. 子组件 <template> <div> ...
- react 父组件调用子组件方法、子组件调用父组件方法
我们闲话不多说,直接上代码 // 父组件 import React, {Component} from 'react'; class Parents extends Component { const ...
- react 中子组件调用父组件的方法
1.在父组件中定义方法,并绑定在子组件上 // 在子组件中调用父组件中的方法 import React,{Component} from 'react'; import Child from './c ...
随机推荐
- [C++]_[获取Utf8字符串的字符个数和子字符串]
场景: 1.有时候须要统计utf8字符串的个数,单纯统计字节个数是不行的. 2.有时候也须要获取从某个位置開始的n个连续字符用于显示或计算. static int GetUtf8LetterNumbe ...
- 数学之路-python计算实战(1)-ubuntu安装pypy
Get the source code. The following packages contain the source at the same revision as the above bin ...
- CentOS yum时出现“Could not retrieve mirrorlist ”的解决的方法——resolv.conf的配置
原因:没有配置resolv.conf 解决方法: 到/etc文件夹下配置resolv.conf增加nameserver IP,如: nameserver 8.8.8.8 nameserver 8.8. ...
- 浅谈API网关(API Gateway)如何承载API经济生态链
序言 API经济生态链已经在全球范围覆盖, 绝大多数企业都已经走在数字化转型的道路上,API成为企业连接业务的核心载体, 并产生巨大的盈利空间.快速增长的API规模以及调用量,使得企业IT在架构上.模 ...
- linux ifconfig命令配置ip地址
Linux下网卡命名规律:eth0,eth1. 第一块以太网卡.第二块. lo为环回接口,它的IP地址固定为127.0.0.1.掩码8位. 它代表你的机器本身. ifconfig [Interfa ...
- pymysql 本地不抱错 连接云数据库报错
import pymysql h, pt, u, p, db = 'rm-2zeoye0j3957bw1w2.mysql.rds.aliyuncs.com', 3306, 'tongji_2017', ...
- ios9--UIImageView的帧动画
// // ViewController.m // 05-UIImageView的帧动画 // #import "ViewController.h" @interface View ...
- Silverlight访问数据库大全(转)
Silverlight访问数据库大全 Silverlight访问数据库大全 Posted on 2010-06-13 17:25 moss_tan_jun 阅读(1917) 评论(0) 编辑 收藏 最 ...
- C#的内存管理知识 .
本章介绍内存管理和内存访问的各个方面.尽管运行库负责为程序员处理大部分内存管理工作,但程序员仍必须理解内存管理的工作原理,了解如何处理未托管的资源. 如果很好地理解了内存管理和C#提供的指针功能,也就 ...
- java 提取主域名
import com.google.common.net.InternetDomainName; public static void main(String[] args) { InternetDo ...