1.JSX:语法糖,对语言的功能并没有影响,但更方便程序员使用,增强可读性。

2.jsFiddle:前端在线调试工具

3.为什么要把this额外声明成_self变量,因为window.setTimeout中的函数内部this指向的是global对象,所以需要在之前保存this变量。

也可以利用apply、call、bind修改this指向。

var Hello = React.createClass({
getInitialState: function () {
return {
opacity: 1.0
};
}, componentDidMount: function () {
this.timer = setInterval(function () {
var opacity = this.state.opacity;
opacity -= .05;
if (opacity < 0.1) {
opacity = 1.0;
}
this.setState({
opacity: opacity
});
}.bind(this), 100);
}, render: function () {
return (
<div style={{opacity: this.state.opacity}}>
Hello {this.props.name}
</div>
);
}
}); ReactDOM.render(
<Hello name="world"/>,
document.body
);

4.实现按钮、输入框的联动

ref属性,找DOM节点时,用refs

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>菜鸟教程 React 实例</title>
<script src="https://cdn.bootcss.com/react/15.4.2/react.min.js"></script>
<script src="https://cdn.bootcss.com/react/15.4.2/react-dom.min.js"></script>
<script src="https://cdn.bootcss.com/babel-standalone/6.22.1/babel.min.js"></script>
</head>
<body>
<div id="container"></div>
<script type="text/babel">
var TestClickComponent = React.createClass({
handleClick:function(event){
var tipE = ReactDOM.findDOMNode(this.refs.tip);
if(tipE.style.display === "none"){
tipE.style.display = "inline";
}else{
tipE.style.display = "none";
}
event.stopPropagation();
event.preventDefault();
},
render:function(){
return (
<div>
<button onClick={this.handleClick}>显示|隐藏</button><span ref="tip">测试点击</span>
</div>
);
}
});
var TestInputComponent = React.createClass({
getInitialState:function(){
return {
inputContent : ""
}
},
handletextInput:function(event){
this.setState({
inputContent:event.target.value
});
},
render:function(){
return (
<div>
<input type="text" onChange={this.handletextInput} /><span>{this.state.inputContent}</span>
</div>
);
}
}); ReactDOM.render(
<div>
<TestClickComponent />
<TestInputComponent />
</div>
,document.getElementById("container")) </script>
</body>
</html>

5.父组件、子组件之间的值传递

最新文章

  1. QT 常用控件二
  2. jquery 模糊查询下拉框
  3. poj2485&amp;&amp;poj2395 kruskal
  4. MVP MVC MVVM 傻傻分不清
  5. Winform跨线程操作界面的策略
  6. 指定的值不是类型“Edm.Int32”的实例
  7. 【转】Android中引入第三方Jar包的方法(java.lang.NoClassDefFoundError解决办法)
  8. highlight a DOM element on mouse over, like inspect does
  9. Android 下使用tcpdump网络抓包方法
  10. QT 打开文件对话框汇总
  11. 多尺度二维离散小波重构waverec2
  12. json_encode详解
  13. Media Player Classic - HC 源代码分析 7:详细信息选项卡(CPPageFileInfoDetails)
  14. Matting任务里的Gradient与Connectivity指标
  15. centos7.2安装图文详解
  16. 【XSY2693】景中人 区间DP
  17. SQL Server Profiler的简单使用
  18. 【分治-前缀积后缀积】JS Window @2018acm徐州邀请赛G
  19. IDEA下搜狗输入法输入中文时卡着不动的参考解决方法
  20. M1事后分析报告

热门文章

  1. 关于C# 委托(delegate)与事件(event)的用法及事例
  2. 腾讯企业邮箱报错 &quot;smtp.exmail.qq.com&quot;port 465, isSSL false
  3. PowerDesigner16导出SQL时如何添加注释
  4. 汇编语言程序环境搭建masm+debug64位 win10/7
  5. &lt;Android 基础(二十三)&gt; Android Studio快捷键
  6. How To Manage StartUp Applications In Ubuntu
  7. The difference between a local variable and a member variable
  8. Netty高性能web框架
  9. spring boot(4)-html和templates
  10. FileWriter与BufferedWriter的适用场景