{"id":1063,"date":"2023-03-12T10:20:12","date_gmt":"2023-03-12T02:20:12","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1063"},"modified":"2023-04-29T11:46:51","modified_gmt":"2023-04-29T03:46:51","slug":"react-js-integrate-antd-component-library","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/12\/react-js-integrate-antd-component-library\/","title":{"rendered":"React.js\u96c6\u6210Antd\u7ec4\u4ef6\u5e93"},"content":{"rendered":"<h2>\u96c6\u6210\u5f15\u7528<\/h2>\n<pre><code>yarn add babel-plugin-import\nyarn add antd<\/code><\/pre>\n<p><!-- more --><\/p>\n<p>\u5b89\u88c5\u5b8c\u6bd5\u540e\uff0c\u9996\u5148\u5728index.js\u4e2d\u5f15\u5165antd\u7684css\u6587\u4ef6<\/p>\n<pre><code class=\"language-javascript\">import &#039;antd\/dist\/antd.css&#039;;<\/code><\/pre>\n<p>\u4e4b\u540e\uff0c\u5728\u9700\u8981\u7528\u5230antd\u7684\u7ec4\u4ef6js\u4e2d\u5f15\u5165\u6240\u9700\u90e8\u4ef6\u5373\u53ef<\/p>\n<pre><code class=\"language-javascript\">import React from &#039;react&#039;;\nimport { Button } from &#039;antd&#039;;\n\nclass AntdTest extends React.Component {\n    clickMe() {\n\n    }\n\n    render() {\n        return (\n            &lt;div className=&quot;App&quot;&gt;\n                &lt;Button type=&quot;primary&quot; onClick={this.clickMe}&gt;Primary&lt;\/Button&gt;\n                &lt;Button&gt;Default&lt;\/Button&gt;\n                &lt;Button type=&quot;dashed&quot;&gt;Dashed&lt;\/Button&gt;\n                &lt;Button type=&quot;danger&quot;&gt;Danger&lt;\/Button&gt;\n            &lt;\/div&gt;\n        );\n    }\n}\n\nexport default AntdTest;<\/code><\/pre>\n<pre><code class=\"language-javascript\">import React from &#039;react&#039;;\nimport { Button } from &#039;antd&#039;;\n\nfunction AntdTest() {\n    return (\n        &lt;div className=&quot;App&quot;&gt;\n            &lt;Button type=&quot;primary&quot;&gt;Primary&lt;\/Button&gt;\n            &lt;Button&gt;Default&lt;\/Button&gt;\n            &lt;Button type=&quot;dashed&quot;&gt;Dashed&lt;\/Button&gt;\n            &lt;Button type=&quot;danger&quot;&gt;Danger&lt;\/Button&gt;\n        &lt;\/div&gt;\n    );\n}\n\nexport default AntdTest;<\/code><\/pre>\n<p>\u800c\u5728IE11\u4e0b\uff0c\u4f1a\u62a5\u4e0d\u652f\u6301startsWith\u7684\u9519<br \/>\n\u9700\u8981\u5b89\u88c5<code>npm install --save babel-polyfill<\/code><br \/>\n\u7136\u540e\u5728\u5165\u53e3\u6587\u4ef6index.js\u4e2d\u5f15\u5165<code>import &#039;babel-polyfill&#039;;<\/code><br \/>\n\u56e0\u4e3astartWith\u662f2015\u5e74\u8bed\u8a00\u89c4\u8303\u91cc\u66f4\u65b0\u7684\uff0cIE\u59cb\u7ec8\u6ca1\u6709\u652f\u6301\uff0c\u9700\u8981\u7528\u4f4e\u7248\u672c\u7684js\u5b9e\u73b0\u9ad8\u7248\u672c\u7684js<\/p>\n<h2>\u7ec4\u4ef6\u64cd\u4f5c<\/h2>\n<pre><code class=\"language-javascript\">import React from &#039;react&#039;;\nimport { Button, notification, Icon } from &#039;antd&#039;;\n\nclass AntdTest extends React.Component {\n    clickMe() {\n        notification.open({\n            message: &#039;Notification Title&#039;,\n            description:\n                &#039;http:\/\/www.appblog.cn&#039;,\n            icon: &lt;Icon type=&quot;smile&quot; style={{ color: &#039;#108ee9&#039; }} \/&gt;,\n        });\n    };\n\n    render() {\n        return (\n            &lt;div className=&quot;App&quot;&gt;\n                &lt;Button type=&quot;primary&quot; onClick={this.clickMe}&gt;Primary&lt;\/Button&gt;\n                &lt;Button&gt;Default&lt;\/Button&gt;\n                &lt;Button type=&quot;dashed&quot;&gt;Dashed&lt;\/Button&gt;\n                &lt;Button type=&quot;danger&quot;&gt;Danger&lt;\/Button&gt;\n            &lt;\/div&gt;\n        );\n    }\n}\n\nexport default AntdTest;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u96c6\u6210\u5f15\u7528 yarn add babel-plugin-import yarn add antd \u5b89\u88c5\u5b8c\u6bd5\u540e\uff0c\u9996 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[287],"class_list":["post-1063","post","type-post","status-publish","format-standard","hentry","category-react","tag-antd"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1063","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1063"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1063\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1063"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1063"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1063"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}