{"id":5829,"date":"2023-01-06T15:10:34","date_gmt":"2023-01-06T07:10:34","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=5829"},"modified":"2023-01-06T15:10:34","modified_gmt":"2023-01-06T07:10:34","slug":"%e4%ba%86%e8%a7%a3react-js%e4%b8%ad%e7%9a%84%e7%94%9f%e5%91%bd%e9%80%b1%e6%9c%9f%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/react-js\/%e4%ba%86%e8%a7%a3react-js%e4%b8%ad%e7%9a%84%e7%94%9f%e5%91%bd%e9%80%b1%e6%9c%9f%e6%96%b9%e6%b3%95\/","title":{"rendered":"\u4e86\u89e3React.js\u4e2d\u7684\u751f\u547d\u9031\u671f\u65b9\u6cd5"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"React.js, \u751f\u547d\u9031\u671f\u65b9\u6cd5, lifecycle methods\"><\/p>\n<h1>React.js \u9762\u8a66\u984c\u76ee\u8b1b\u89e3\uff1a\u4ec0\u9ebc\u662f\u751f\u547d\u9031\u671f\u65b9\u6cd5(lifecycle methods)\uff0c\u6709\u54ea\u4e9b\uff1f<\/h1>\n<p>React.js \u662f\u4e00\u500b\u7528\u65bc\u69cb\u5efa\u7528\u6236\u754c\u9762\u7684 JavaScript \u5eab\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e00\u7a2e\u53ef\u4ee5\u66f4\u8f15\u9b06\u5730\u69cb\u5efa\u7528\u6236\u754c\u9762\u7684\u65b9\u6cd5\u3002\u5b83\u7684\u4e00\u500b\u91cd\u8981\u7279\u6027\u662f\u751f\u547d\u9031\u671f\u65b9\u6cd5\uff08lifecycle methods\uff09\uff0c\u5b83\u5011\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u66f4\u597d\u5730\u63a7\u5236\u7d44\u4ef6\u7684\u884c\u70ba\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5011\u5c07\u8a73\u7d30\u4ecb\u7d39\u4ec0\u9ebc\u662f\u751f\u547d\u9031\u671f\u65b9\u6cd5\uff0c\u4ee5\u53ca\u5b83\u5011\u6709\u54ea\u4e9b\u3002<\/p>\n<h2>\u4ec0\u9ebc\u662f\u751f\u547d\u9031\u671f\u65b9\u6cd5\uff1f<\/h2>\n<p>\u751f\u547d\u9031\u671f\u65b9\u6cd5\u662f React.js \u4e2d\u7684\u4e00\u7a2e\u7279\u6b8a\u65b9\u6cd5\uff0c\u5b83\u5011\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u66f4\u597d\u5730\u63a7\u5236\u7d44\u4ef6\u7684\u884c\u70ba\u3002\u5b83\u5011\u53ef\u4ee5\u5728\u7d44\u4ef6\u7684\u751f\u547d\u9031\u671f\u4e2d\u88ab\u8abf\u7528\uff0c\u4ee5\u63a7\u5236\u7d44\u4ef6\u7684\u6e32\u67d3\u548c\u66f4\u65b0\u3002<\/p>\n<p>\u751f\u547d\u9031\u671f\u65b9\u6cd5\u53ef\u4ee5\u88ab\u5206\u70ba\u4e09\u500b\u985e\u5225\uff1a<\/p>\n<ul>\n<li><strong>Mounting\uff1a<\/strong> \u9019\u4e9b\u65b9\u6cd5\u6703\u5728\u7d44\u4ef6\u88ab\u6e32\u67d3\u5230 DOM \u4e0a\u6642\u8abf\u7528\uff0c\u5b83\u5011\u53ef\u4ee5\u7528\u65bc\u521d\u59cb\u5316\u7d44\u4ef6\u7684\u72c0\u614b\uff0c\u6216\u8005\u8a2d\u7f6e\u4e00\u4e9b\u8a02\u95b1\u3002<\/li>\n<li><strong>Updating\uff1a<\/strong> \u9019\u4e9b\u65b9\u6cd5\u6703\u5728\u7d44\u4ef6\u7684 props \u6216 state \u66f4\u65b0\u6642\u8abf\u7528\uff0c\u5b83\u5011\u53ef\u4ee5\u7528\u65bc\u66f4\u65b0\u7d44\u4ef6\u7684\u72c0\u614b\uff0c\u6216\u8005\u6aa2\u67e5 props \u662f\u5426\u6539\u8b8a\u3002<\/li>\n<li><strong>Unmounting\uff1a<\/strong> \u9019\u4e9b\u65b9\u6cd5\u6703\u5728\u7d44\u4ef6\u5f9e DOM \u4e0a\u79fb\u9664\u6642\u8abf\u7528\uff0c\u5b83\u5011\u53ef\u4ee5\u7528\u65bc\u6e05\u7406\u7d44\u4ef6\u7684\u72c0\u614b\uff0c\u6216\u8005\u53d6\u6d88\u8a02\u95b1\u3002<\/li>\n<\/ul>\n<p><!--more--><\/p>\n<h2>\u6709\u54ea\u4e9b\u751f\u547d\u9031\u671f\u65b9\u6cd5\uff1f<\/h2>\n<p>React.js \u63d0\u4f9b\u4e86\u8a31\u591a\u751f\u547d\u9031\u671f\u65b9\u6cd5\uff0c\u5b83\u5011\u53ef\u4ee5\u88ab\u5206\u70ba\u4e09\u500b\u985e\u5225\uff1aMounting\u3001Updating \u548c Unmounting\u3002<\/p>\n<h3>Mounting \u751f\u547d\u9031\u671f\u65b9\u6cd5<\/h3>\n<ul>\n<li><strong>constructor()<\/strong>\uff1a\u5728\u7d44\u4ef6\u88ab\u6e32\u67d3\u4e4b\u524d\u8abf\u7528\uff0c\u5b83\u53ef\u4ee5\u7528\u65bc\u521d\u59cb\u5316\u7d44\u4ef6\u7684\u72c0\u614b\uff0c\u6216\u8005\u8a2d\u7f6e\u4e00\u4e9b\u8a02\u95b1\u3002<\/li>\n<li><strong>componentWillMount()<\/strong>\uff1a\u5728\u7d44\u4ef6\u88ab\u6e32\u67d3\u4e4b\u524d\u8abf\u7528\uff0c\u5b83\u53ef\u4ee5\u7528\u65bc\u66f4\u65b0\u7d44\u4ef6\u7684\u72c0\u614b\uff0c\u6216\u8005\u6aa2\u67e5 props \u662f\u5426\u6539\u8b8a\u3002<\/li>\n<li><strong>render()<\/strong>\uff1a\u5728\u7d44\u4ef6\u88ab\u6e32\u67d3\u4e4b\u524d\u8abf\u7528\uff0c\u5b83\u53ef\u4ee5\u7528\u65bc\u6e05\u7406\u7d44\u4ef6\u7684\u72c0\u614b\uff0c\u6216\u8005\u53d6\u6d88\u8a02\u95b1\u3002<\/li>\n<li><strong>componentDidMount()<\/strong>\uff1a\u5728\u7d44\u4ef6\u88ab\u6e32\u67d3\u4e4b\u5f8c\u8abf\u7528\uff0c\u5b83\u53ef\u4ee5\u7528\u65bc\u66f4\u65b0\u7d44\u4ef6\u7684\u72c0\u614b\uff0c\u6216\u8005\u6aa2\u67e5 props \u662f\u5426\u6539\u8b8a\u3002<\/li>\n<\/ul>\n<h3>Updating \u751f\u547d\u9031\u671f\u65b9\u6cd5<\/h3>\n<ul>\n<li><strong>componentWillReceiveProps()<\/strong>\uff1a\u5728\u7d44\u4ef6\u63a5\u6536\u5230\u65b0\u7684 props \u6642\u8abf\u7528\uff0c\u5b83\u53ef\u4ee5\u7528\u65bc\u66f4\u65b0\u7d44\u4ef6\u7684\u72c0\u614b\uff0c\u6216\u8005\u6aa2\u67e5 props \u662f\u5426\u6539\u8b8a\u3002<\/li>\n<li><strong>shouldComponentUpdate()<\/strong>\uff1a\u5728\u7d44\u4ef6\u7684 props \u6216 state \u66f4\u65b0\u6642\u8abf\u7528\uff0c\u5b83\u53ef\u4ee5\u7528\u65bc\u6e05\u7406\u7d44\u4ef6\u7684\u72c0\u614b\uff0c\u6216\u8005\u53d6\u6d88\u8a02\u95b1\u3002<\/li>\n<li><strong>componentWillUpdate()<\/strong>\uff1a\u5728\u7d44\u4ef6\u7684 props \u6216 state \u66f4\u65b0\u4e4b\u524d\u8abf\u7528\uff0c\u5b83\u53ef\u4ee5\u7528\u65bc\u66f4\u65b0\u7d44\u4ef6\u7684\u72c0\u614b\uff0c\u6216\u8005\u6aa2\u67e5 props \u662f\u5426\u6539\u8b8a\u3002<\/li>\n<li><strong>render()<\/strong>\uff1a\u5728\u7d44\u4ef6\u7684 props \u6216 state \u66f4\u65b0\u4e4b\u5f8c\u8abf\u7528\uff0c\u5b83\u53ef\u4ee5\u7528\u65bc\u6e05\u7406\u7d44\u4ef6\u7684\u72c0\u614b\uff0c\u6216\u8005\u53d6\u6d88\u8a02\u95b1\u3002<\/li>\n<li><strong>componentDidUpdate()<\/strong>\uff1a\u5728\u7d44\u4ef6\u7684 props \u6216 state \u66f4\u65b0\u4e4b\u5f8c\u8abf\u7528\uff0c\u5b83\u53ef\u4ee5\u7528\u65bc\u66f4\u65b0\u7d44\u4ef6\u7684\u72c0\u614b\uff0c\u6216\u8005\u6aa2\u67e5 props \u662f\u5426\u6539\u8b8a\u3002<\/li>\n<\/ul>\n<h3>Unmounting \u751f\u547d\u9031\u671f\u65b9\u6cd5<\/h3>\n<ul>\n<li><strong>componentWillUnmount()<\/strong>\uff1a\u5728\u7d44\u4ef6\u88ab\u5f9e DOM \u4e0a\u79fb\u9664\u4e4b\u524d\u8abf\u7528\uff0c\u5b83\u53ef\u4ee5\u7528\u65bc\u6e05\u7406\u7d44\u4ef6\u7684\u72c0\u614b\uff0c\u6216\u8005\u53d6\u6d88\u8a02\u95b1\u3002<\/li>\n<\/ul>\n<p>\u751f\u547d\u9031\u671f\u65b9\u6cd5\u662f React.js \u4e2d\u7684\u4e00\u7a2e\u91cd\u8981\u7279\u6027\uff0c\u5b83\u5011\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u66f4\u597d\u5730\u63a7\u5236\u7d44\u4ef6\u7684\u884c\u70ba\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5011\u8a73\u7d30\u4ecb\u7d39\u4e86\u4ec0\u9ebc\u662f\u751f\u547d\u9031\u671f\u65b9\u6cd5\uff0c\u4ee5\u53ca\u5b83\u5011\u6709\u54ea\u4e9b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981\uff1aReact.js\u7684\u751f\u547d\u9031\u671f\u65b9\u6cd5\u662f\u4e00\u7a2e\u7279\u6b8a\u7684\u51fd\u6578\uff0c\u5b83\u5011\u53ef\u4ee5\u5728React\u7d44\u4ef6\u7684\u751f\u547d\u9031\u671f\u4e2d\u88ab\u8abf\u7528\uff0c\u4ee5\u63a7\u5236\u7d44\u4ef6\u7684\u884c\u70ba\u3002\u672c\u6587\u5c07\u8a73\u7d30\u4ecb\u7d39React.js\u4e2d\u7684\u751f\u547d\u9031\u671f\u65b9\u6cd5\uff0c\u4ee5\u53ca\u5b83\u5011\u7684\u529f\u80fd\u548c\u7528\u9014\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[184,183],"tags":[182,181],"class_list":["post-5829","post","type-post","status-publish","format-standard","hentry","category-react","category-react-js","tag-react","tag-react-js"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1w1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5829","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/comments?post=5829"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5829\/revisions"}],"predecessor-version":[{"id":5830,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5829\/revisions\/5830"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=5829"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=5829"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=5829"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}