react组件的生命周期
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>react dome
</title>
<script src="./build/react.js"></script>
<script src="./build/react-dom.js"></script>
<script src="./build/browser.min.js"></script>
</head>
<body>
<div id="container"></div>
<script type="text/babel">
var Demo = React.createClass({
getDefaultProps:function () {
console.log("getDefaultProps");
return {};
},
getInitialState:function () {
console.log("getInitialState");
return null;
},
componentWillMount:function () {
console.log("componentWillMount");
},
render:function () {
console.log("render");
return <div>hello react</div>;
},
componentDidMount:function () {
console.log("componentDidMount");
},
componentWillReceiveProps:function () {
console.log("componentWillReceiveProps");
},
shouldComponentUpdate:function () {
console.log("shouldComponentUpdate");
return true;
},
componentUpdate:function () {
console.log("componentUpdate");
},
componentDidUpdate:function () {
console.log("componentDidUpdate");
},
componentWillUnmount:function () {
console.log("componentWillUnmount");
}
})
ReactDOM.render(
<Demo/>,
document.getElementById("container")
)
//重新渲染组件
ReactDOM.render(
<Demo/>,
document.getElementById("container")
)
//移除组件
ReactDOM.unmountComponentAtNode(
document.getElementById("container")
)
</script>
</body>
</html>
转载请注明原文地址: https://www.6miu.com/read-66539.html