1 Star 0 Fork 0

Hanley / study-front

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
43th.html 1.37 KB
一键复制 编辑 原始数据 按行查看 历史
hanley 提交于 2018-07-25 22:22 . react component lifecycle
<!DOCTYPE html>
<html>
<head>
<title>react-声明周期+style示例</title>
<meta charset="UTF-8" />
<script src='node_modules/react/umd/react.development.js'></script>
<script src='node_modules/react-dom/umd/react-dom.development.js'></script>
<script src='node_modules/babel-standalone/babel.min.js'></script>
</head>
<body>
<div id="my"></div>
<script type="text/babel">
class Hello extends React.Component{
constructor(){
super();
this.state = {
opacity:1
};
};
componentDidMount () {
console.log('组件完成挂载');
this.timer = setInterval(()=>{
var num = this.state.opacity;
num -=0.05;
if(num<0.1){
num =1;
}
this.setState({
opacity:num
});
},500)
};
componentWillUnmount(){
console.log('在组件从 DOM 中移除的时候立刻被调用');
clearInterval(this.timer);
}
render(){
return (
<div style={{opacity:this.state.opacity}}>
hello world
</div>
)
}
};
ReactDOM.render(
<Hello/>,
document.getElementById('my')
)
</script>
</body>
</html>
1
https://gitee.com/thanlin/study.git
git@gitee.com:thanlin/study.git
thanlin
study
study-front
master

搜索帮助