React componentDidMount

Posted ThisCall

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了React componentDidMount相关的知识,希望对你有一定的参考价值。

<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script src="js/react.js"></script>
<script src="js/react-dom.js"></script>
<script src="js/browser.min.js"></script>
</head>
<body>
<div id="example"></div>

<script type="text/babel">
var LifeComponent = React.createClass({
componentDidMount:function(){
setInterval(
function(){
var nowValue = this.state.opacityValue;
nowValue+=0.1;
if(nowValue > 1)
{
nowValue = 0;
}

this.setState({opacityValue:nowValue},function(){
console.log(this.state.opacityValue);
});

}.bind(this),100
)
},
getInitialState:function(){
return {opacityValue:0}
},
render:function(){
return <div style={{opacity:this.state.opacityValue}}>
Hello LifeCycle
</div>
}
})

ReactDOM.render(
<LifeComponent/>,
document.getElementById(‘example‘)
)

</script>

</body>
</html>

以上是关于React componentDidMount的主要内容,如果未能解决你的问题,请参考以下文章

React componentDidMount

async/await 不适用于 ComponentDidMount 中的 react.js

text #react #componentDidMount

React componentDidMount“解析错误:缺少分号”

Apollo + React:数据未出现在 componentDidMount 生命周期中

React componentDidMount() 初始化状态