{"id":4546,"date":"2023-01-04T16:06:06","date_gmt":"2023-01-04T08:06:06","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=4546"},"modified":"2023-01-04T16:06:06","modified_gmt":"2023-01-04T08:06:06","slug":"%e5%ad%b8%e7%bf%92react-js%e7%88%b6%e5%ad%90%e7%b5%84%e4%bb%b6%e9%80%9a%e4%bf%a1props%e7%9a%84%e5%9f%ba%e7%a4%8e%e7%9f%a5%e8%ad%98","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/react-js\/%e5%ad%b8%e7%bf%92react-js%e7%88%b6%e5%ad%90%e7%b5%84%e4%bb%b6%e9%80%9a%e4%bf%a1props%e7%9a%84%e5%9f%ba%e7%a4%8e%e7%9f%a5%e8%ad%98\/","title":{"rendered":"\u5b78\u7fd2React.js\u7236\u5b50\u7d44\u4ef6\u901a\u4fe1(props)\u7684\u57fa\u790e\u77e5\u8b58"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"React, \u7236\u5b50\u7d44\u4ef6\u901a\u4fe1, props\"><\/p>\n<p>React \u7236\u5b50\u7d44\u4ef6\u901a\u4fe1(props)\u662f React \u958b\u767c\u4e2d\u4e00\u500b\u91cd\u8981\u7684\u6982\u5ff5\uff0c\u5b83\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u5728\u7d44\u4ef6\u9593\u50b3\u905e\u8cc7\u6599\uff0c\u8b93\u958b\u767c\u8005\u53ef\u4ee5\u66f4\u6709\u6548\u7387\u7684\u958b\u767c\u51fa\u66f4\u591a\u529f\u80fd\u3002\u672c\u6587\u5c07\u4ecb\u7d39 React \u7236\u5b50\u7d44\u4ef6\u901a\u4fe1(props)\u7684\u57fa\u672c\u6982\u5ff5\uff0c\u4ee5\u53ca\u5982\u4f55\u4f7f\u7528 props \u4f86\u50b3\u905e\u8cc7\u6599\u3002<\/p>\n<h2>\u4ec0\u9ebc\u662f React \u7236\u5b50\u7d44\u4ef6\u901a\u4fe1(props)<\/h2>\n<p>React \u7236\u5b50\u7d44\u4ef6\u901a\u4fe1(props)\u662f React \u958b\u767c\u4e2d\u4e00\u500b\u91cd\u8981\u7684\u6982\u5ff5\uff0c\u5b83\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u5728\u7d44\u4ef6\u9593\u50b3\u905e\u8cc7\u6599\uff0c\u8b93\u958b\u767c\u8005\u53ef\u4ee5\u66f4\u6709\u6548\u7387\u7684\u958b\u767c\u51fa\u66f4\u591a\u529f\u80fd\u3002<\/p>\n<h2>\u5982\u4f55\u4f7f\u7528 props \u4f86\u50b3\u905e\u8cc7\u6599<\/h2>\n<p>\u4f7f\u7528 props \u4f86\u50b3\u905e\u8cc7\u6599\u662f React \u958b\u767c\u4e2d\u6700\u5e38\u898b\u7684\u65b9\u5f0f\uff0c\u5b83\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u5728\u7d44\u4ef6\u9593\u50b3\u905e\u8cc7\u6599\uff0c\u8b93\u958b\u767c\u8005\u53ef\u4ee5\u66f4\u6709\u6548\u7387\u7684\u958b\u767c\u51fa\u66f4\u591a\u529f\u80fd\u3002<\/p>\n<h2>\u7236\u5b50\u7d44\u4ef6\u901a\u4fe1(props)\u7684\u7bc4\u4f8b<\/h2>\n<p>\u4e0b\u9762\u662f\u4e00\u500b\u7c21\u55ae\u7684\u7236\u5b50\u7d44\u4ef6\u901a\u4fe1(props)\u7684\u7bc4\u4f8b\uff0c\u5b83\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u66f4\u6e05\u695a\u7684\u4e86\u89e3\u5982\u4f55\u4f7f\u7528 props \u4f86\u50b3\u905e\u8cc7\u6599\uff1a<\/p>\n<pre class=\"brush: javascript\">\n\/\/ \u7236\u7d44\u4ef6\nclass Parent extends React.Component {\n  render() {\n    return (\n      <Child name=\"John\" age=\"20\" \/>\n    );\n  }\n}\n\n\/\/ \u5b50\u7d44\u4ef6\nclass Child extends React.Component {\n  render() {\n    return (\n      <div>\n        Name: {this.props.name}\n        Age: {this.props.age}\n      <\/div>\n    );\n  }\n}\n<\/pre>\n<p>\u5728\u4e0a\u9762\u7684\u7bc4\u4f8b\u4e2d\uff0c\u6211\u5011\u53ef\u4ee5\u770b\u5230\u7236\u7d44\u4ef6\u50b3\u905e\u4e86\u4e00\u500b\u540d\u70ba <code>name<\/code> \u548c <code>age<\/code> \u7684 props \u7d66\u5b50\u7d44\u4ef6\uff0c\u5b50\u7d44\u4ef6\u53ef\u4ee5\u4f7f\u7528 <code>this.props.name<\/code> \u548c <code>this.props.age<\/code> \u4f86\u53d6\u5f97\u50b3\u905e\u7684\u8cc7\u6599\u3002<\/p>\n<p><!--more--><\/p>\n<h2>\u7e3d\u7d50<\/h2>\n<p>React \u7236\u5b50\u7d44\u4ef6\u901a\u4fe1(props)\u662f React \u958b\u767c\u4e2d\u4e00\u500b\u91cd\u8981\u7684\u6982\u5ff5\uff0c\u5b83\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u5728\u7d44\u4ef6\u9593\u50b3\u905e\u8cc7\u6599\uff0c\u8b93\u958b\u767c\u8005\u53ef\u4ee5\u66f4\u6709\u6548\u7387\u7684\u958b\u767c\u51fa\u66f4\u591a\u529f\u80fd\u3002\u672c\u6587\u4ecb\u7d39\u4e86 React \u7236\u5b50\u7d44\u4ef6\u901a\u4fe1(props)\u7684\u57fa\u672c\u6982\u5ff5\uff0c\u4ee5\u53ca\u5982\u4f55\u4f7f\u7528 props \u4f86\u50b3\u905e\u8cc7\u6599\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2React.js\u7236\u5b50\u7d44\u4ef6\u901a\u4fe1(props)\u7684\u57fa\u790e\u77e5\u8b58\uff0c\u4e86\u89e3\u5982\u4f55\u4f7f\u7528props\u5728\u7236\u5b50\u7d44\u4ef6\u4e4b\u9593\u50b3\u905e\u8cc7\u6599\uff0c\u4ee5\u53ca\u5982\u4f55\u5728\u7236\u7d44\u4ef6\u4e2d\u66f4\u65b0\u5b50\u7d44\u4ef6\u7684\u72c0\u614b\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-4546","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-1bk","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/4546","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=4546"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/4546\/revisions"}],"predecessor-version":[{"id":4547,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/4546\/revisions\/4547"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=4546"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=4546"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=4546"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}