{"id":27452,"date":"2024-11-24T15:59:36","date_gmt":"2024-11-24T07:59:36","guid":{"rendered":"https:\/\/fwq.ai\/blog\/27452\/"},"modified":"2024-11-24T15:59:36","modified_gmt":"2024-11-24T07:59:36","slug":"antd-%e4%b8%ad%e5%a6%82%e4%bd%95%e5%ae%9e%e7%8e%b0%e5%8f%af%e6%bb%9a%e5%8a%a8%e8%a1%a8%e6%a0%bc%ef%bc%8c%e5%b9%b6%e4%bd%bf%e5%85%b6%e9%ab%98%e5%ba%a6%e8%87%aa%e9%80%82%e5%ba%94%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/27452\/","title":{"rendered":"Antd \u4e2d\u5982\u4f55\u5b9e\u73b0\u53ef\u6eda\u52a8\u8868\u683c\uff0c\u5e76\u4f7f\u5176\u9ad8\u5ea6\u81ea\u9002\u5e94\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173124668458808.jpg\" class=\"aligncenter\" title=\"Antd \u4e2d\u5982\u4f55\u5b9e\u73b0\u53ef\u6eda\u52a8\u8868\u683c\uff0c\u5e76\u4f7f\u5176\u9ad8\u5ea6\u81ea\u9002\u5e94\uff1f\u63d2\u56fe\" alt=\"Antd \u4e2d\u5982\u4f55\u5b9e\u73b0\u53ef\u6eda\u52a8\u8868\u683c\uff0c\u5e76\u4f7f\u5176\u9ad8\u5ea6\u81ea\u9002\u5e94\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>antd \u4e2d\u7528\u4e8e\u5c55\u793a\u53ef\u6eda\u52a8\u5185\u5bb9\u7684\u7ec4\u4ef6<\/strong><\/p>\n<p>\u5728\u5f00\u53d1\u4e2d\uff0c\u5f53\u5185\u5bb9\u8f83\u591a\u65f6\uff0c\u9875\u9762\u4f1a\u9690\u85cf\u4e0b\u65b9\u7684\u90e8\u5206\u3002\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0cant design (antd) \u63d0\u4f9b\u4e86\u591a\u79cd\u7ec4\u4ef6\uff0c\u53ef\u4ee5\u8fdb\u884c\u5305\u5bb9\u6240\u6709\u7684\u5185\u5bb9\uff0c\u5e76\u5728\u5185\u5bb9\u6ea2\u51fa\u65f6\u5b9e\u73b0\u6eda\u52a8\u3002<\/p>\n<p><strong>card \u4e0e table \u7684\u7ed3\u5408<\/strong><\/p>\n<p>\u5728 antd \u4e2d\uff0c\u53ef\u4ee5\u5c06 card \u7ec4\u4ef6\u4e0e table \u7ec4\u4ef6\u7ed3\u5408\u4f7f\u7528\uff0c\u5b9e\u73b0\u5185\u5bb9\u6ea2\u51fa\u65f6\u7684\u6eda\u52a8\u6548\u679c\u3002card \u7ec4\u4ef6\u7528\u4e8e\u5305\u88f9 table \u7ec4\u4ef6\uff0c\u5e76\u8bbe\u7f6e height \u548c  \u5c5e\u6027\uff0c\u4f7f\u5176\u5728\u5185\u5bb9\u6ea2\u51fa\u65f6\u80fd\u591f\u6eda\u52a8\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>import react from 'react';\nimport { card, table } from 'antd';\n\nconst columns = [\n  \/\/ \u8868\u683c\u5217\u7684\u914d\u7f6e\n];\n\nconst data = [\n  \/\/ \u8868\u683c\u6570\u636e\u7684\u914d\u7f6e\n];\n\nconst scrollabletable = () =&gt; {\n  return (\n    &lt;card style={{ height: '400px', overflow: 'auto' }}&gt;\n      &lt;table\n        columns={columns}\n        datasource={data}\n        pagination={{ pagesize: 50 }}\n        scroll={{ y: 300 }}\n      \/&gt;\n    &lt;\/card&gt;\n  );\n};\n\nexport default scrollabletable;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6837\u5f0f\u8c03\u6574<\/strong><\/p>\n<p>\u53ef\u4ee5\u6839\u636e\u9700\u8981\u8fdb\u4e00\u6b65\u8c03\u6574\u6837\u5f0f\uff0c\u4ee5\u9002\u5e94\u5177\u4f53\u7684\u9700\u6c42\u3002\u4e0a\u8ff0\u4ee3\u7801\u793a\u4f8b\u8bbe\u7f6e\u4e86\u8868\u683c\u7684\u9ad8\u5ea6\u4e3a300px\uff0c\u53ef\u4ee5\u6839\u636e\u5b9e\u9645\u60c5\u51b5\u8fdb\u884c\u8c03\u6574\u3002\u901a\u8fc7\u4f7f\u7528 card \u7ec4\u4ef6\u5305\u88f9 table \u7ec4\u4ef6\uff0c\u5e76\u8bbe\u7f6e\u9002\u5f53\u7684\u6837\u5f0f\uff0c\u53ef\u4ee5\u5b9e\u73b0\u5185\u5bb9\u6ea2\u51fa\u65f6\u7684\u6eda\u52a8\u6548\u679c\u3002<\/p>\n<p><strong>\u4f7f\u7528 flex \u5e03\u5c40\u81ea\u9002\u5e94\u9ad8\u5ea6<\/strong><\/p>\n<p>\u8981\u8ba9 card \u7ec4\u4ef6\u6839\u636e\u5176\u7236\u5bb9\u5668\u7684\u9ad8\u5ea6\u8fdb\u884c\u81ea\u9002\u5e94\uff0c\u800c\u4e0d\u662f\u56fa\u5b9a\u9ad8\u5ea6\uff0c\u53ef\u4ee5\u4f7f\u7528  \u7684 flex \u5e03\u5c40\u6765\u5b9e\u73b0\u3002\u60a8\u53ef\u4ee5\u5c06 height: &#8216;400px&#8217; \u66ff\u6362\u4e3a height: &#8216;100%&#8217;\uff0c\u5e76\u5728 css \u4e2d\u8bbe\u7f6e flex \u5e03\u5c40\u5c5e\u6027\uff1a<\/p>\n<pre>import react from 'react';\nimport { card, table } from 'antd';\nimport '.\/scrollabletable.css'; \/\/ \u5f15\u5165\u81ea\u5b9a\u4e49\u7684css\n\nconst columns = [\n  \/\/ \u8868\u683c\u5217\u7684\u914d\u7f6e\n];\n\nconst data = [\n  \/\/ \u8868\u683c\u6570\u636e\u7684\u914d\u7f6e\n];\n\nconst scrollabletable = () =&gt; {\n  return (\n    &lt;div classname=\"container\"&gt;\n      &lt;card classname=\"card\"&gt;\n        &lt;table\n          columns={columns}\n          datasource={data}\n          pagination={{ pagesize: 50 }}\n          scroll={{ y: '100%' }}\n        \/&gt;\n      &lt;\/card&gt;\n    &lt;\/div&gt;\n  );\n};\n\nexport default scrollabletable;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>scrollabletable.css<\/strong><\/p>\n<pre>\/* ScrollableTable.css *\/\n.container {\n  height: 100vh;\n  display: flex;\n  flex-direction: column;\n}\n\n.card {\n  height: 100%;\n  display: flex;\n  flex-direction: column;\n}\n\n.card .ant-table-wrapper {\n  flex: 1;\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u901a\u8fc7\u4ee5\u4e0a\u4fee\u6539\uff0ccard \u7ec4\u4ef6\u5c06\u6839\u636e\u7236\u5bb9\u5668\u7684\u9ad8\u5ea6\u81ea\u9002\u5e94\uff0c\u5e76\u4e14\u8868\u683c\u5185\u5bb9\u53ef\u4ee5\u6eda\u52a8\u663e\u793a\u3002\u8fd9\u6837\u5c31\u53ef\u4ee5\u907f\u514d\u4f7f\u7528\u56fa\u5b9a\u9ad8\u5ea6\uff0c\u5e76\u786e\u4fdd\u5e03\u5c40\u5728\u4e0d\u540c\u5c4f\u5e55\u5c3a\u5bf8\u4e0b\u7684\u81ea\u9002\u5e94\u6027\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fAntd \u4e2d\u5982\u4f55\u5b9e\u73b0\u53ef\u6eda\u52a8\u8868\u683c\uff0c\u5e76\u4f7f\u5176\u9ad8\u5ea6\u81ea\u9002\u5e94\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>antd \u4e2d\u7528\u4e8e\u5c55\u793a\u53ef\u6eda\u52a8\u5185\u5bb9\u7684\u7ec4\u4ef6 \u5728\u5f00\u53d1\u4e2d\uff0c\u5f53\u5185\u5bb9\u8f83\u591a\u65f6\uff0c\u9875\u9762\u4f1a\u9690\u85cf\u4e0b\u65b9\u7684\u90e8\u5206\u3002\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0cant design (antd) \u63d0\u4f9b\u4e86\u591a\u79cd\u7ec4\u4ef6\uff0c\u53ef\u4ee5\u8fdb\u884c\u5305\u5bb9\u6240\u6709\u7684\u5185\u5bb9\uff0c\u5e76\u5728\u5185\u5bb9\u6ea2\u51fa\u65f6\u5b9e\u73b0\u6eda\u52a8\u3002 card \u4e0e table \u7684\u7ed3\u5408 \u5728 antd \u4e2d\uff0c\u53ef\u4ee5\u5c06 card \u7ec4\u4ef6\u4e0e table \u7ec4\u4ef6\u7ed3\u5408\u4f7f\u7528\uff0c\u5b9e\u73b0\u5185\u5bb9\u6ea2\u51fa\u65f6\u7684\u6eda\u52a8\u6548\u679c\u3002card \u7ec4\u4ef6\u7528\u4e8e\u5305\u88f9 table \u7ec4\u4ef6\uff0c\u5e76\u8bbe\u7f6e height \u548c \u5c5e\u6027\uff0c\u4f7f\u5176\u5728\u5185\u5bb9\u6ea2\u51fa\u65f6\u80fd\u591f\u6eda\u52a8\u3002\u4f8b\u5982\uff1a import react from &#8216;react&#8217;; import { card, table } from &#8216;antd&#8217;; const columns = [ \/\/ \u8868\u683c\u5217\u7684\u914d\u7f6e ]; const data = [ \/\/ \u8868\u683c\u6570\u636e\u7684\u914d\u7f6e ]; const scrollabletable = () =&gt; { return [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-27452","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27452","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=27452"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27452\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=27452"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=27452"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=27452"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}