【react】慕课网视频学习笔记
2024-09-17 09:50:14
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.父组件、子组件之间的值传递
最新文章
- QT 常用控件二
- jquery 模糊查询下拉框
- poj2485&;&;poj2395 kruskal
- MVP MVC MVVM 傻傻分不清
- Winform跨线程操作界面的策略
- 指定的值不是类型“Edm.Int32”的实例
- 【转】Android中引入第三方Jar包的方法(java.lang.NoClassDefFoundError解决办法)
- highlight a DOM element on mouse over, like inspect does
- Android 下使用tcpdump网络抓包方法
- QT 打开文件对话框汇总
- 多尺度二维离散小波重构waverec2
- json_encode详解
- Media Player Classic - HC 源代码分析 7:详细信息选项卡(CPPageFileInfoDetails)
- Matting任务里的Gradient与Connectivity指标
- centos7.2安装图文详解
- 【XSY2693】景中人 区间DP
- SQL Server Profiler的简单使用
- 【分治-前缀积后缀积】JS Window @2018acm徐州邀请赛G
- IDEA下搜狗输入法输入中文时卡着不动的参考解决方法
- M1事后分析报告
热门文章
- 关于C# 委托(delegate)与事件(event)的用法及事例
- 腾讯企业邮箱报错 ";smtp.exmail.qq.com";port 465, isSSL false
- PowerDesigner16导出SQL时如何添加注释
- 汇编语言程序环境搭建masm+debug64位 win10/7
- <;Android 基础(二十三)>; Android Studio快捷键
- How To Manage StartUp Applications In Ubuntu
- The difference between a local variable and a member variable
- Netty高性能web框架
- spring boot(4)-html和templates
- FileWriter与BufferedWriter的适用场景