import React from 'react';
import ReactDOM from 'react-dom';
import $ from 'jquery';
//var $ = require('jquery'); $("#hello").html("hello22888888888888888888888"); class Animal {
constructor(){
this.type = 'animal'
}
says(say){
console.log(this.type + ' says ' + say)
}
} let animal = new Animal()
animal.says('hello') //animal says hello class Cat extends Animal {
constructor(){
super();
this.type = 'cat'
}
} let cat = new Cat()
let ii=(i)=>{return i+13+6};
cat.says('hello:'+ ii(3)) //cat says hello function animals(...types){
console.log(types)
}
animals('cat', 'dog', 'fish') let cat1 = 'ken';
let dog = 'lili';
let zoo = {cat1, dog};
console.log(zoo) class Content extends React.Component {
render () {
return (
<div>
<input ref="myInput" type="text" value={this.props.myDataProp} onChange={this.props.updateStateProp} />
<h4>{this.props.myDataProp}</h4>
</div>
)
}
}; class HelloMessage extends React.Component {
constructor(props){
super(props);
this.state={
value: 'Hello Runoob!',
label:"hee"
}
} handleChange(event) {
// this.setState({value: event.target.value});
let d= new Date();
//this.refs.myInput2.focus();
this.setState({
value: event.target.value,
label: event.target.value ? event.target.value : d.getTime()
});
console.log(this.state)
}
handleChange2(event) {
// this.setState({value: event.target.value});
let d= new Date();
console.log('handleChange2:'+event.target.value) } render () {
//var value = this.state.value;
return (
<div>
<Content myDataProp = {this.state.value} updateStateProp = {this.handleChange.bind(this)}></Content>
<button onClick={this.handleChange2.bind(this)}>点我</button>
<h4>label:{this.state.label}</h4> <CustomTextInput />
</div>
)
}
}; class CustomTextInput extends React.Component {
constructor(props) {
super(props);
this.focus = this.focus.bind(this);
this.name="ssss";
} focus() {
// Explicitly focus the text input using the raw DOM API
this.textInput.focus();
} render() {
// Use the `ref` callback to store a reference to the text input DOM
// element in an instance field (for example, this.textInput).
return (
<div>
<input type="text" ref={(input) => { this.textInput = input; } } />
<input type="button" value="Focus the text input" onClick={this.focus} />
</div>
)
}
} ReactDOM.render( <HelloMessage />, document.getElementById('example')); //孙子,将下拉选项的值传给爷爷 class Grandson extends React.Component {
render() {
return (
<div>性别:
<select onChange={this.props.handleSelect}>
<option value="男">男</option>
<option value="女">女</option>
</select>
</div>
)
}
};
//子,将用户输入的姓名传给爹
//对于孙子的处理函数,父只需用props传下去即可
class Child extends React.Component {
//var Child = React.createClass({
render() {
return (
<div>
姓名:<input onChange={this.props.handleVal}/>
<Grandson handleSelect={this.props.handleSelect}/>
</div>
)
}
};
//父组件,准备了两个state,username和sex用来接收子孙传过来的值,对应两个函数handleVal和handleSelect
class Parent extends React.Component { constructor(props) {
super(props);
this.state={
username: '',
sex: ''
} } handleVal(event){
this.setState({username: event.target.value});
}
handleSelect(event) {
this.setState({sex: event.target.value});
}
render(){
return (
<div>
<div>用户姓名:{this.state.username}</div>
<div>用户性别:{this.state.sex}</div>
<Child handleVal={this.handleVal.bind(this)} handleSelect={this.handleSelect.bind(this)}/>
</div>
)
}
};
ReactDOM.render(
<Parent />,
document.getElementById('root')
);

react 父子传值的更多相关文章

  1. React(7) --react父子组件传参

    react父子组件传参 父级向子级传参:在父组件中,我们引入子组件,通过给子组件添加属性,来起到传参的作用,子组件可以通过props获取父组件传过来的参数. 在父组件中: import React f ...

  2. 10.4 Vue 父子传值

    简单示例 APP.vue <template> <div> <img :src="imgSrc"> <!-- 父子传值 --> &l ...

  3. Vue父子传值

    昨天创建完项目以后,今日首先使用项目来做一个简单的导航栏体会一下Vue的使用 1.项目的结构: 2.首先在Vheader.Vue中编辑代码: <template> <header c ...

  4. day 100天 VUE 父子传值,单页面.

     一 .静态资源导入方法 启动服务  npm run serve <template> <div id ="app"> <h3>{{msg}}& ...

  5. 基于vue-cli,测试非父子传值时,碰到 keep-alive的神奇

    非父子传值测试 一直都很好奇非父子传值到底如何,结果入坑许久才爬出来,才知道在脚手架里测试就是坑. 问题: 测试非父子传值时,由于组件之间是通过路由进行跳转,值传过去又被刷掉 思路: 因为路由跳转,相 ...

  6. React父子组件的一个混淆点

    反正我自己是混淆了,React父子组件和组件类的继承弄混在一起了.这两个东西完全是不相关的. 父子组件可以看成两个组件标签的包含关系,在另外一个组件标签的内部就是子组件,父子组件通过这种关系通信. 组 ...

  7. vue传值(父子传值,非父子传值)

    vue组件传值,分为父子传值和非父子传值,父子传值又分为父传子和子传父. 组件之间的传值,实现了数据的联动,是从操作Dom到操作数据一个跳转性的突破,在学习vue双向绑定原理之后, 这种观念就应该继续 ...

  8. Vue中的父子传值问题

    个人网站 https://iiter.cn 程序员导航站 开业啦,欢迎各位观众姥爷赏脸参观,如有意见或建议希望能够不吝赐教! 好久没更博了,感觉下班后的时间莫名其妙就没有了,有了,了... 趁着端午放 ...

  9. Blazor和Vue对比学习(基础1.3):属性和父子传值

    组件除了要解决视图层展示.视图层与逻辑层的数据绑定,还需要解决一个重大问题,就是在组件树中实现数据传递,包括了父到子.子到父.祖到孙,以及任意组织之间.而我们上一章讲到的实现双向绑定的两个指令,Vue ...

随机推荐

  1. DDD领域驱动之干货(二)

       基于仓储的实现 1.前言:本着第一节写的有些糊涂,主要是自己喜欢实干,不太喜欢用文字表述,就这样吧.下面切入正题. 博客园里面有很多的大佬,我这里就不一一解释概览,有兴趣的朋友可以去看大佬们写的 ...

  2. css font-family(字体样式)

    之前因为用的很少,所以没注意,最近做APP混合开发, 给字体一个样式    font-family:" 微软雅黑": 发现在有的手机上有效,但是在有的手机上是无效的, 解决方法:  ...

  3. GitHub的使用方法

    版本控制系统 > Git 分布式 > Subversion 集中式 1. 安装git: # apt-get install git //root权限 $ sudo apt-get inst ...

  4. 是否要从单片机转为嵌入式Linux?

    作者:嵌入式老鸟火哥 授权转载于公众号嵌入式老鸟的职场之道(ID: ict_embedded),有增加内容和修改. 最近很多童鞋投票并咨询如何从单片机转为嵌入式Linux开发.看来读者圈中做单片机,R ...

  5. spark运行模式之二:Spark的Standalone模式安装部署

    Spark运行模式 Spark 有很多种模式,最简单就是单机本地模式,还有单机伪分布式模式,复杂的则运行在集群中,目前能很好的运行在 Yarn和 Mesos 中,当然 Spark 还有自带的 Stan ...

  6. UTC与本地时间字符串互相转换

    #!/usr/bin/env python import time import datetime # 格式自改 UTC_FORMAT = '%Y-%m-%dT%H:%M:%SZ' LOCAL_FOR ...

  7. 转 vs2008使用技巧推荐

    Visual Studio 2008自带的1000多个 Windows 系统使用的各种图标.光标和动画文件在Visual Studio 2008的安装目录下,\Microsoft Visual Stu ...

  8. 性能测试之Jmeter学习(二)

    一.Jmeter的基本操作 1.添加|移除测试元件 2.加载和保存测试元件 3.配置测试对中的测试元件 4.保存测试计划 5.运行测试计划 6.终止测试 7.错误报告 二.Jmeter体系结构 注释: ...

  9. A - Set of Strings

    Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Description You ar ...

  10. 带着问题看 react-redux 源码实现

    前言 Redux作为通用的状态管理器,可以搭配任意界面框架.所以并搭配react使用的话就要借助redux官方提供的React绑定库react-redux,以高效灵活的在react中使用redux.下 ...