{"id":4696,"date":"2023-01-04T17:40:22","date_gmt":"2023-01-04T09:40:22","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=4696"},"modified":"2023-01-04T17:40:22","modified_gmt":"2023-01-04T09:40:22","slug":"%e8%a7%a3%e6%b1%bareact-js%e4%b8%ad%e7%9a%84typeerrorcannotreadpropertyvalueofundefined%e9%8c%af%e8%aa%a4","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/react-js\/%e8%a7%a3%e6%b1%bareact-js%e4%b8%ad%e7%9a%84typeerrorcannotreadpropertyvalueofundefined%e9%8c%af%e8%aa%a4\/","title":{"rendered":"\u89e3\u6c7aReact.js\u4e2d\u7684&#8221;TypeError:Cannotreadproperty&#8217;value&#8217;ofundefined&#8221;\u932f\u8aa4"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"React.js, TypeError, Cannot read property 'value' of undefined\"><\/p>\n<h1>\u89e3\u6c7a React.js &#8220;TypeError: Cannot read property &#8216;value&#8217; of undefined&#8221; \u932f\u8aa4<\/h1>\n<p>React.js \u662f\u4e00\u500b\u7528\u65bc\u69cb\u5efa\u7528\u6236\u754c\u9762\u7684 JavaScript \u5eab\uff0c\u5b83\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u66f4\u8f15\u9b06\u5730\u69cb\u5efa\u9ad8\u6027\u80fd\u7684\u7db2\u9801\u61c9\u7528\u7a0b\u5e8f\u3002\u7136\u800c\uff0c\u5728\u4f7f\u7528 React.js \u6642\uff0c\u958b\u767c\u8005\u53ef\u80fd\u6703\u9047\u5230\u4e00\u4e9b\u5e38\u898b\u7684\u932f\u8aa4\uff0c\u5176\u4e2d\u4e4b\u4e00\u5c31\u662f &#8220;TypeError: Cannot read property &#8216;value&#8217; of undefined&#8221;\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5011\u5c07\u8a73\u7d30\u4ecb\u7d39\u5982\u4f55\u89e3\u6c7a\u9019\u500b\u554f\u984c\u3002<\/p>\n<h2>\u4ec0\u9ebc\u662f &#8220;TypeError: Cannot read property &#8216;value&#8217; of undefined&#8221; \u932f\u8aa4\uff1f<\/h2>\n<p>&#8220;TypeError: Cannot read property &#8216;value&#8217; of undefined&#8221; \u932f\u8aa4\u662f React.js \u4e2d\u6700\u5e38\u898b\u7684\u932f\u8aa4\u4e4b\u4e00\uff0c\u5b83\u8868\u660e\u4f60\u6b63\u5728\u5617\u8a66\u8b80\u53d6\u4e00\u500b\u672a\u5b9a\u7fa9\u7684\u5c6c\u6027\u3002\u9019\u500b\u932f\u8aa4\u901a\u5e38\u6703\u5728\u4f60\u5617\u8a66\u8b80\u53d6\u4e00\u500b\u672a\u5b9a\u7fa9\u7684\u8b8a\u91cf\u6642\u767c\u751f\uff0c\u6216\u8005\u7576\u4f60\u5617\u8a66\u8b80\u53d6\u4e00\u500b\u672a\u5b9a\u7fa9\u7684\u5c0d\u8c61\u5c6c\u6027\u6642\u767c\u751f\u3002<\/p>\n<h2>\u5982\u4f55\u89e3\u6c7a &#8220;TypeError: Cannot read property &#8216;value&#8217; of undefined&#8221; \u932f\u8aa4\uff1f<\/h2>\n<p>\u8981\u89e3\u6c7a &#8220;TypeError: Cannot read property &#8216;value&#8217; of undefined&#8221; \u932f\u8aa4\uff0c\u4f60\u9700\u8981\u78ba\u4fdd\u4f60\u6b63\u5728\u8b80\u53d6\u7684\u8b8a\u91cf\u6216\u5c0d\u8c61\u5c6c\u6027\u5df2\u7d93\u88ab\u5b9a\u7fa9\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528 <code>typeof<\/code> \u904b\u7b97\u7b26\u4f86\u6aa2\u67e5\u4e00\u500b\u8b8a\u91cf\u662f\u5426\u5df2\u7d93\u88ab\u5b9a\u7fa9\uff0c\u5982\u679c\u8b8a\u91cf\u672a\u5b9a\u7fa9\uff0c\u5247 <code>typeof<\/code> \u904b\u7b97\u7b26\u6703\u8fd4\u56de <code>undefined<\/code>\u3002<\/p>\n<pre class=\"brush: javascript\">\nif (typeof myVariable !== 'undefined') {\n  \/\/ myVariable \u5df2\u7d93\u88ab\u5b9a\u7fa9\n}\n<\/pre>\n<p>\u4f60\u4e5f\u53ef\u4ee5\u4f7f\u7528 <code>hasOwnProperty()<\/code> \u65b9\u6cd5\u4f86\u6aa2\u67e5\u4e00\u500b\u5c0d\u8c61\u662f\u5426\u5177\u6709\u6307\u5b9a\u7684\u5c6c\u6027\uff0c\u5982\u679c\u5c0d\u8c61\u5177\u6709\u6307\u5b9a\u7684\u5c6c\u6027\uff0c\u5247 <code>hasOwnProperty()<\/code> \u65b9\u6cd5\u6703\u8fd4\u56de <code>true<\/code>\uff0c\u5426\u5247\u6703\u8fd4\u56de <code>false<\/code>\u3002<\/p>\n<pre class=\"brush: javascript\">\nif (myObject.hasOwnProperty('myProperty')) {\n  \/\/ myObject \u5177\u6709 myProperty \u5c6c\u6027\n}\n<\/pre>\n<p>\u53e6\u5916\uff0c\u4f60\u9084\u53ef\u4ee5\u4f7f\u7528 <code>try\/catch<\/code> \u8a9e\u53e5\u4f86\u6355\u7372\u53ef\u80fd\u767c\u751f\u7684\u932f\u8aa4\uff0c\u4e26\u5728\u767c\u751f\u932f\u8aa4\u6642\u57f7\u884c\u7279\u5b9a\u7684\u64cd\u4f5c\u3002<\/p>\n<pre class=\"brush: javascript\">\ntry {\n  \/\/ \u5617\u8a66\u8b80\u53d6\u4e00\u500b\u672a\u5b9a\u7fa9\u7684\u8b8a\u91cf\n  console.log(myVariable);\n} catch (e) {\n  \/\/ \u5982\u679c\u767c\u751f\u932f\u8aa4\uff0c\u5247\u57f7\u884c\u7279\u5b9a\u7684\u64cd\u4f5c\n  console.log('myVariable \u672a\u5b9a\u7fa9');\n}\n<\/pre>\n<h2>\u7e3d\u7d50<\/h2>\n<p>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5011\u8a73\u7d30\u4ecb\u7d39\u4e86\u5982\u4f55\u89e3\u6c7a React.js \u4e2d\u6700\u5e38\u898b\u7684\u932f\u8aa4\u4e4b\u4e00\uff1a&#8221;TypeError: Cannot read property &#8216;value&#8217; of undefined&#8221;\u3002\u6211\u5011\u5efa\u8b70\u4f60\u4f7f\u7528 <code>typeof<\/code> \u904b\u7b97\u7b26\u3001<code>hasOwnProperty()<\/code> \u65b9\u6cd5\u548c <code>try\/catch<\/code> \u8a9e\u53e5\u4f86\u6aa2\u67e5\u8b8a\u91cf\u548c\u5c0d\u8c61\u5c6c\u6027\u662f\u5426\u5df2\u7d93\u88ab\u5b9a\u7fa9\uff0c\u4ee5\u907f\u514d\u51fa\u73fe\u6b64\u985e\u932f\u8aa4\u3002<\/p>\n<p><!--more--><\/p>\n<p>\u5982\u679c\u4f60\u9084\u6709\u4efb\u4f55\u7591\u554f\uff0c\u8acb\u5728\u4e0b\u9762\u7684\u8a55\u8ad6\u5340\u7559\u8a00\uff0c\u6211\u5011\u6703\u76e1\u5feb\u70ba\u4f60\u89e3\u7b54\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u89e3\u6c7aReact.js\u4e2d\u5e38\u898b\u7684&#8221;TypeError:Cannotreadproperty&#8217;value&#8217;ofundefined&#8221;\u932f\u8aa4\uff0c\u4e26\u63d0\u4f9b\u4e00\u4e9b\u6709\u7528\u7684\u6280\u5de7\u548c\u6307\u5c0e\uff0c\u4ee5\u5e6b\u52a9\u958b\u767c\u8005\u89e3\u6c7a\u6b64\u985e\u554f\u984c\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-4696","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-1dK","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/4696","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=4696"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/4696\/revisions"}],"predecessor-version":[{"id":4697,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/4696\/revisions\/4697"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=4696"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=4696"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=4696"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}