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. plsql导入cvs 时提示missing right parenthesis

    删除自动生成的时间格式值,如:SQL function框里自动生成的值

  2. flume 日志收集单节点

    flume 是 cloudera公司研发的日志收集系统,采用3层结构:1. agent层,用于直接收集日志;2.connect 层,用于接受日志; 3. 数据存储层,用于保存日志.由一到多个maste ...

  3. 组合数学中的常见定理&组合数的计算&取模

    组合数的性质: C(n,m)=C(n,n-m); C(n,m)=n!/(m!(n-m)!); 组合数的递推公式: C(n,m)=  C(n-1,m-1)+C(n-1,m); 组合数一般数值较大,题目会 ...

  4. 解除win10禁ping方法

    在局域网中,有一台电脑安装了win10操作系统,win10电脑连接网络没有问题,就是在其他电脑ping这台windows10电脑时就是ping不通,显示“请求超时.”.虽然这台windows10电脑联 ...

  5. 爬虫库之BeautifulSoup学习(一)

    Beautiful Soup的简介 简单来说,Beautiful Soup是python的一个库,最主要的功能是从网页抓取数据. 官方解释如下: Beautiful Soup提供一些简单的.pytho ...

  6. Flex屏蔽并自定义鼠标右键菜单

    http://www.cnblogs.com/wuhenke/archive/2010/01/29/1659353.html Google Code上有一个RightClickManager的项目. ...

  7. 在linux上部署tomcat服务

    在linux上部署tomcat 1.安装JDK 2.下载tomcat http://tomcat.apache.org/download-70.cgi 3.上传到服务器,并解压 4.上传war包或者已 ...

  8. CSS动画的性能分析和浏览器GPU加速

    此文已由作者袁申授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 有数的数据大屏可以在一块屏幕上展示若干张不同的图表,以炫酷的方式展示各种业务数据.其中有些图表使用CSS实现了 ...

  9. 719. Find K-th Smallest Pair Distance

    Given an integer array, return the k-th smallest distance among all the pairs. The distance of a pai ...

  10. OPENGL0_简介

    opengl定义: Open Graphics Library,开放图形程序接口,跨平台,跨语言.提供了与底层图形硬件的接口,是一个功能强大的底层图形库. opengl库种类: gl:核心库,常规,核 ...