{"id":4688,"date":"2023-01-04T17:36:07","date_gmt":"2023-01-04T09:36:07","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=4688"},"modified":"2023-01-04T17:36:07","modified_gmt":"2023-01-04T09:36:07","slug":"%e8%a7%a3%e6%b1%bareact-js%e4%b8%ad%e7%9a%84%e3%80%8cstyleprop%e9%8c%af%e8%aa%a4%e3%80%8d","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/react-js\/%e8%a7%a3%e6%b1%bareact-js%e4%b8%ad%e7%9a%84%e3%80%8cstyleprop%e9%8c%af%e8%aa%a4%e3%80%8d\/","title":{"rendered":"\u89e3\u6c7aReact.js\u4e2d\u7684\u300cStyleProp\u932f\u8aa4\u300d"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"React.js, Error, Style Prop, Mapping, Style Properties, Values, String, JSX\"><\/p>\n<h1>\u89e3\u6c7a React.js &#8220;Error: The style prop expects a mapping from style properties to values, not a string. For example, style={{marginRight: spacing + &#8217;em&#8217;}} when using JSX.&#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\u932f\u8aa4\uff0c\u5176\u4e2d\u4e00\u500b\u662f\u201cError: The style prop expects a mapping from style properties to values, not a string. For example, style={{marginRight: spacing + &#8217;em&#8217;}} when using JSX.\u201d\u3002<\/p>\n<p>\u9019\u500b\u932f\u8aa4\u8868\u660e\uff0c\u5728\u4f7f\u7528 JSX \u6642\uff0cstyle \u5c6c\u6027\u671f\u671b\u7684\u662f\u4e00\u500b\u5c07\u6a23\u5f0f\u5c6c\u6027\u6620\u5c04\u5230\u503c\u7684\u6620\u5c04\uff0c\u800c\u4e0d\u662f\u4e00\u500b\u5b57\u7b26\u4e32\u3002\u56e0\u6b64\uff0c\u8981\u89e3\u6c7a\u9019\u500b\u932f\u8aa4\uff0c\u958b\u767c\u8005\u9700\u8981\u5c07 style \u5c6c\u6027\u8a2d\u7f6e\u70ba\u4e00\u500b\u5c07\u6a23\u5f0f\u5c6c\u6027\u6620\u5c04\u5230\u503c\u7684\u5c0d\u8c61\uff0c\u800c\u4e0d\u662f\u4e00\u500b\u5b57\u7b26\u4e32\u3002<\/p>\n<p><!--more--><\/p>\n<p>\u8209\u4f8b\u4f86\u8aaa\uff0c\u5982\u679c\u958b\u767c\u8005\u60f3\u8981\u5c07 marginRight \u8a2d\u7f6e\u70ba spacing + &#8217;em&#8217;\uff0c\u4ed6\u5011\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u78bc\uff1a<\/p>\n<pre class=\"brush: javascript\">\nstyle={{marginRight: spacing + 'em'}}\n<\/pre>\n<p>\u9019\u6a23\uff0cReact.js \u5c31\u6703\u5c07 marginRight \u8a2d\u7f6e\u70ba spacing + &#8217;em&#8217;\uff0c\u800c\u4e0d\u6703\u51fa\u73fe\u932f\u8aa4\u3002<\/p>\n<p>\u6b64\u5916\uff0c\u958b\u767c\u8005\u9084\u53ef\u4ee5\u4f7f\u7528 JavaScript \u4e2d\u7684\u8b8a\u91cf\u4f86\u8a2d\u7f6e\u6a23\u5f0f\u5c6c\u6027\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre class=\"brush: javascript\">\nlet marginRight = spacing + 'em';\nstyle={{marginRight: marginRight}}\n<\/pre>\n<p>\u9019\u6a23\uff0cReact.js \u5c31\u6703\u5c07 marginRight \u8a2d\u7f6e\u70ba spacing + &#8217;em&#8217;\uff0c\u800c\u4e0d\u6703\u51fa\u73fe\u932f\u8aa4\u3002<\/p>\n<p>\u7e3d\u4e4b\uff0c\u8981\u89e3\u6c7a React.js \u201cError: The style prop expects a mapping from style properties to values, not a string. For example, style={{marginRight: spacing + &#8217;em&#8217;}} when using JSX.\u201d \u932f\u8aa4\uff0c\u958b\u767c\u8005\u9700\u8981\u5c07 style \u5c6c\u6027\u8a2d\u7f6e\u70ba\u4e00\u500b\u5c07\u6a23\u5f0f\u5c6c\u6027\u6620\u5c04\u5230\u503c\u7684\u5c0d\u8c61\uff0c\u800c\u4e0d\u662f\u4e00\u500b\u5b57\u7b26\u4e32\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u89e3\u6c7aReact.js\u4e2d\u7684\u300cStyleProp\u932f\u8aa4\u300d\uff0c\u4e26\u63d0\u4f9b\u4e00\u4e9b\u6709\u7528\u7684\u6280\u5de7\uff0c\u8b93\u958b\u767c\u8005\u53ef\u4ee5\u66f4\u8f15\u9b06\u5730\u4f7f\u7528React.js\u4f86\u5275\u5efa\u51fa\u8c50\u5bcc\u7684\u7db2\u9801\u61c9\u7528\u7a0b\u5f0f\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-4688","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-1dC","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/4688","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=4688"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/4688\/revisions"}],"predecessor-version":[{"id":4689,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/4688\/revisions\/4689"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=4688"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=4688"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=4688"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}