{"id":212,"date":"2021-02-10T10:20:47","date_gmt":"2021-02-10T02:20:47","guid":{"rendered":"http:\/\/gjweb.top\/?p=212"},"modified":"2021-02-10T10:20:47","modified_gmt":"2021-02-10T02:20:47","slug":"react%e9%a1%b9%e7%9b%ae%e5%88%9d%e5%a7%8b%e5%8c%96","status":"publish","type":"post","link":"https:\/\/gjweb.top\/?p=212","title":{"rendered":"react\u9879\u76ee\u521d\u59cb\u5316"},"content":{"rendered":"\n<ol class=\"wp-block-list\"><li>\u4f18\u5316import<\/li><li>\u4f7f\u7528styled-components<\/li><li>\u7edf\u4e00css<\/li><li>React-router<\/li><li>\u4f7f\u7528SVG\u56fe\u7247<\/li><li><\/li><\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">1.\u4f18\u5316import<\/h2>\n\n\n\n<p>\u5728tscinfig.json\u4e2d\u6dfb\u52a0,\u53ef\u4ee5\u5427src\u5f53\u505a\u6839\u76ee\u5f55\u8def\u76f4\u63a5import &#8220;app.tsx&#8221;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> &nbsp; &nbsp;\"compilerOptions\": {<br> &nbsp; &nbsp; &nbsp; &nbsp;+ &nbsp;\"baseUrl\": \"src\",<br> &nbsp;  }<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">2. \u4f7f\u7528styled-components<\/h2>\n\n\n\n<p>\u4f7f\u7528styled-components\u8fdb\u884ccss<\/p>\n\n\n\n<p>\u5b89\u88c5<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> &nbsp; &nbsp;yarn add styled-components<br> &nbsp; &nbsp;yarn add --dev @types\/styled-components<\/pre>\n\n\n\n<p>\u4f7f\u7528<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> &nbsp; &nbsp;import styled from 'styled-components'<br> &nbsp; &nbsp;const Button = styled.button`<br> &nbsp; &nbsp; &nbsp;color:red<br> &nbsp; &nbsp;`<br> &nbsp; &nbsp;const App = ()=&gt;{<br> &nbsp; &nbsp; &nbsp; &nbsp;return (<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;Button&gt;&lt;\/Button&gt;<br> &nbsp; &nbsp; &nbsp;  )<br> &nbsp;  }<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">3. \u7edf\u4e00css<\/h2>\n\n\n\n<p>\u5728scss\u6216\u8005css\u6587\u4ef6\u4e2d\u6dfb\u52a0<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> &nbsp; &nbsp;@ihelpermport-normalize;<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">4. React-router<\/h2>\n\n\n\n<p><a href=\"https:\/\/reactrouter.com\/web\/guides\/quick-start\">\u53c2\u8003\u6587\u6863<\/a><\/p>\n\n\n\n<p>\u8bbe\u7f6e404\u9875\u9762<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> &nbsp; &nbsp;&lt;Switch&gt;<br> &nbsp; &nbsp; &nbsp; &nbsp;&lt;Route path=\"*\"&gt;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;404,\u9875\u9762\u4e0d\u5b58\u5728<br> &nbsp; &nbsp; &nbsp; &nbsp;&lt;\/Route&gt;<br> &nbsp; &nbsp;&lt;\/Switch&gt;<\/pre>\n\n\n\n<p>\u8bbe\u7f6e\u9ed8\u8ba4\u663e\u793a\u9875<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> &nbsp; &nbsp;&lt;Switch&gt;<br> &nbsp; &nbsp; &nbsp; &nbsp;&lt;Redirect exact from=\"\/\" to=\"\/money\"&gt;<br> &nbsp; &nbsp;&lt;\/Switch&gt;<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">5. \u8de8\u5e73\u53f0CSS\u4e2d\u6587\u5b57\u4f53\u89e3\u51b3\u65b9\u6848<\/h2>\n\n\n\n<p><a href=\"https:\/\/zenozeng.github.io\/fonts.css\/\">\u4e2d\u6587\u5b57\u4f53 css github<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">6. \u4f7f\u7528SVG\u56fe\u7247<\/h2>\n\n\n\n<p>\u5982\u679c\u5728\u9879\u76ee\u4e2d\u4f7f\u7528SVG\u56fe\u7247,\u9700\u8981\u501f\u52a9svg-sprite-loader\u8fdb\u884c\u7f16\u8bd1 \u914d\u7f6e\u65b9\u6cd5\u5982\u4e0b<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>\u663e\u793areact\u7684\u914d\u7f6e\u6587\u4ef6<\/li><\/ol>\n\n\n\n<pre class=\"wp-block-preformatted\"> &nbsp; &nbsp;yarn eject<\/pre>\n\n\n\n<ol class=\"wp-block-list\" start=\"2\"><li>\u5b89\u88c5svg-sprite-loader<\/li><\/ol>\n\n\n\n<pre class=\"wp-block-preformatted\"> &nbsp; &nbsp;yarn add --dev svg-sprite-loader<br> &nbsp; &nbsp;yarn add --dev svgo-loader<br> &nbsp; &nbsp;<\/pre>\n\n\n\n<ol class=\"wp-block-list\" start=\"3\"><li>\u914d\u7f6econfig\/webpack.config.js<\/li><\/ol>\n\n\n\n<pre class=\"wp-block-preformatted\">    oneOf:[\n        {\n          test: \/\\.svg$\/,\n          use: [\n            { loader: 'svg-sprite-loader', options: {} },\n            {loader:'svgo-loader',options:{}}\n          ]\n        }\n    ]<\/pre>\n\n\n\n<p>svgo-loader:SVG\u4f18\u5316 svg-transform-loader: \u5bf9SVG\u56fe\u7247\u8fdb\u884c\u4f18\u5316(\u4e0d\u9700\u8981)<\/p>\n\n\n\n<p>4.\u914d\u7f6e\u5b8c\u6210\u540e\u9700\u8981\u91cd\u65b0\u8fd0\u884c\u9879\u76ee<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">    yarn start<\/pre>\n\n\n\n<ol class=\"wp-block-list\" start=\"5\"><li>\u5f15\u5165SVG\u56fe\u7247<\/li><\/ol>\n\n\n\n<pre class=\"wp-block-preformatted\">    require(\"..\/icons\/test.svg\")\n    &lt;svg fill=\"red\" className=\"className\"&gt;\n        &lt;use xlinkHref=\"#test(\u6587\u4ef6\u540d)\"\/&gt;\n    &lt;svg&gt;<\/pre>\n\n\n\n<p>==\u5982\u679c\u4f7f\u7528import xx from &#8220;&#8221;\u5f15\u5165\u4f1a\u89e6\u53d1TreeShaking\u673a\u5236,react\u4f1a\u81ea\u52a8\u5220\u9664==<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f18\u5316import \u4f7f\u7528styled-components \u7edf\u4e00css React-router \u4f7f\u7528SVG\u56fe\u7247 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27],"tags":[],"class_list":["post-212","post","type-post","status-publish","format-standard","hentry","category-27"],"_links":{"self":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts\/212","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=212"}],"version-history":[{"count":0,"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts\/212\/revisions"}],"wp:attachment":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=212"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=212"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=212"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}