<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="./node_modules/react/umd/react.development.js"></script>
<script src="./node_modules/react-dom/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>
<script type="text/babel">
/* function Son(props){
return(
<div>
<p>你好啊</p>
{props.parname}
</div>
)
}; */
class Son extends React.Component{
constructor(props){
super(props);
};
 
componentDidMount(){
this.callback()
}
callback(){
console.log(this.props)
}
render(){
 
return(
<div>
<button onClick={()=>this.props.show('bai')}>你好啊</button>
<button onClick={()=>this.callback()}>yellow</button>
{this.props.parname}
</div>
)
}
}
//如果这里要用onClick={this.callback}的话,它的就会报错很多时候()=>see()表示一个函数
class App extends React.Component{
constructor(props){
super(props)
this.state={
name:'lishishi'
}
}
hand(e){
this.setState({
name:e
})
 
}
render(){
let name='lishishi';
return(
<div>
<p>66666</p>
<Son parname={this.state.name} show={(e)=>this.hand(e)} />
</div>
)
}
}
window.onload=function(){
let titl =document.getElementById("div1");
ReactDOM.render(
<App/>,
titl
)
}
//document.getElementById()
</script>
</head>
<body>
<div id="div1">
</div>
</body>
</html>

react子传父的更多相关文章

  1. vue 组件之间相互传值 父传子 子传父

    1.父传子 把要传入的值放到父标签里  子组件使用props接收 父写法 子写法 2.子传父 子组件: childrenOnclick() { // 发布自定义事件 this.$emit(" ...

  2. Vue父子组件传值 | 父传子 | 子传父

    父传子 父容器 <template> <div> <zdy :module='test'></zdy> </div> </templa ...

  3. Vue ---- 组价 组件化 子传父 父传子

    目录 补充js的for循环: 组件 1.组件的分类: 2.组件的特点 3.创建局部组件 4.全局组件 二.组件化 一.组件传参父传子 二.组件传参:子传父 补充js的for循环: // for in遍 ...

  4. vue的组件通讯 父传子 -- 子传父-- 兄弟组件的传值 vue的组件传值

    首先文字简单撸一下 父子传子   -------首先在父组件上绑定一个属性,在子组件里用props接收,可以是数组或者是对象 子传父   ------在父组件升上自定义一个方法,在子组件里通过this ...

  5. vue子传父、父传子

    子传父 vue子传父使用$emit传值 子组件: <template> <div> <button @click="toParent">点击传到 ...

  6. Vue-组件传值:子传父和兄弟组件间常见的传值方式

    前言 上篇介绍了我对vue组件化的理解和父组件对子组件传值的方式,这篇介绍下常见的子传父和兄弟组件间的传值方式 目录 子组件向父组件传值 任意组件间的传值方式 正文 子组件向父组件传值 关键知识点:$ ...

  7. vue传参子传父

    vue子传父用$emit实现 1.文件目录结构 2.parent父组件内容 <template> <div class="wrap"> <div> ...

  8. Blazor和Vue对比学习(基础1.4):事件和子传父

    Blazor和Vue的组件事件,都使用事件订阅者模式.相对于上一章的组件属性,需要多绕一个弯,无论Blazor还是Vue,都是入门的第一个难点.要突破这个难点,一是要熟悉事件订阅模式<其实不难& ...

  9. React组件介绍与使用(父传子、子传父、兄弟传)

    1.创建组件的方法     1.1.函数式无状态组件 1.1.1.语法 1 function myComponent(props) { 2 return 3 <div>Hello {pro ...

随机推荐

  1. Effective Java 第三版——64. 通过对象的接口引用对象

    Tips 书中的源代码地址:https://github.com/jbloch/effective-java-3e-source-code 注意,书中的有些代码里方法是基于Java 9 API中的,所 ...

  2. [sh]top添加到crontab不生效问题解决

    今天遇到个小问题 top结果赋值给变量,放到文件做处理, 但是不生效问题. https://www.phpbulo.com/archives/509.html cat top.sh NAME=&quo ...

  3. 无法加载协定为“ServiceReference1.xxxxxx”的终结点配置部分,因为找到了该协定的多个终结点配置。请按名称指示首选的终结点配置部分。

    原因是在web.config 文件中多次引用了“添加外部引用” <system.serviceModel> <bindings> <basicHttpBinding> ...

  4. Selenium IDE 基本概念

    要学会Selenium不难,难的是首先你懂不懂测试.没有测试的基础知识,没有对测试理论的实践和认知,没有对测试领域的情感和钻研精神,学会了Selenium这个工具对事情也没有实际帮助. 我是一个技术思 ...

  5. Java编程的逻辑 (93) - 函数式数据处理 (下)

    本系列文章经补充和完善,已修订整理成书<Java编程的逻辑>,由机械工业出版社华章分社出版,于2018年1月上市热销,读者好评如潮!各大网店和书店有售,欢迎购买,京东自营链接:http:/ ...

  6. 启动matlab时总是直接跳转到安装界面的解决方案

    [关于2017双11过后MATLAB许可过期问题的解决方案] 在距离双11还有2个月之前,matlab会提示:Your MATLAB license will expire in 50 days -- ...

  7. VSCode之快捷键和常用插件

    前言 介绍一下我在VSCode中常用的一些快捷方式: ctrl+上下箭头 上下滚动页面 Ctrl+Shift+K 删除某一行 Alt+ ↑ / ↓ 移动某一行 Shift+Alt + ↓ / ↑ 复制 ...

  8. 使用cnpm 安装vue.js

    前提已经安装了node.js 一.临时使用 1.npm install -g cnpm --registry=https://registry.npm.taobao.org 2.cnpm instal ...

  9. js和jquery获取textarea输入的内容

    document.getElementById('textarea').value; $("#textarea").val()

  10. node-sass 安装失败 Failed at the node-sass@4.9.2 postinstall script的解决

    控制台运行npm install时报错,报错信息如下: npm ERR! code ELIFECYCLEnpm ERR! errno 1npm ERR! node-sass@4.9.2 postins ...