{"id":3021,"date":"2024-11-10T15:25:59","date_gmt":"2024-11-10T07:25:59","guid":{"rendered":"https:\/\/fwq.ai\/blog\/3021\/"},"modified":"2024-11-10T15:25:59","modified_gmt":"2024-11-10T07:25:59","slug":"%e5%a6%82%e4%bd%95%e8%87%aa%e5%ae%9a%e4%b9%89-el-table-%e5%90%88%e5%b9%b6%e8%a1%8c%e6%82%ac%e6%b5%ae%e6%a0%b7%e5%bc%8f%e5%92%8c%e9%80%bb%e8%be%91%ef%bc%8c%e5%ae%9e%e7%8e%b0%e9%bc%a0%e6%a0%87%e6%82%ac","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/3021\/","title":{"rendered":"\u5982\u4f55\u81ea\u5b9a\u4e49 el-table \u5408\u5e76\u884c\u60ac\u6d6e\u6837\u5f0f\u548c\u903b\u8f91\uff0c\u5b9e\u73b0\u9f20\u6807\u60ac\u505c\u6548\u679c\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173096814364743.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u81ea\u5b9a\u4e49 el-table \u5408\u5e76\u884c\u60ac\u6d6e\u6837\u5f0f\u548c\u903b\u8f91\uff0c\u5b9e\u73b0\u9f20\u6807\u60ac\u505c\u6548\u679c\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u81ea\u5b9a\u4e49 el-table \u5408\u5e76\u884c\u60ac\u6d6e\u6837\u5f0f\u548c\u903b\u8f91\uff0c\u5b9e\u73b0\u9f20\u6807\u60ac\u505c\u6548\u679c\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u81ea\u5b9a\u4e49 el-table \u5408\u5e76\u884c\u60ac\u6d6e\u6837\u5f0f\u548c\u903b\u8f91\uff1f<\/strong><\/p>\n<p>\u5728\u7ebf demo \u7684\u6548\u679c\u4e2d\uff1a<\/p>\n<ul>\n<li> <strong>\u6548\u679c 1\uff1a<\/strong>\u9f20\u6807\u60ac\u505c\u5728\u7b2c\u4e00\u884c\u65f6\uff0c\u53ea\u9ad8\u4eae\u53f3\u4fa7\uff08\u6216\u6240\u6709\u884c\u9ad8\u4eae\u5408\u5e76\u884c\uff09\u3002<\/li>\n<li> <strong>\u6548\u679c 2\uff1a<\/strong>\u9f20\u6807\u60ac\u505c\u5728\u5408\u5e76\u884c\u65f6\uff0c\u89e6\u53d1\u6240\u6709\u884c\u9ad8\u4eae\u3002<\/li>\n<\/ul>\n<p><strong>\u5982\u4f55\u5b9e\u73b0\uff1a<\/strong><\/p>\n<p>\u8981\u5b9e\u73b0\u4e0a\u8ff0\u6548\u679c\uff0c\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u4fee\u6539\u4ee3\u7801\uff1a<\/p>\n<ol>\n<li><strong>\u4fee\u6539\u60ac\u6d6e\u6837\u5f0f\uff1a<\/strong><\/li>\n<\/ol>\n<pre>.el-table__row.expanded {\n  background-color: #f5f7fa!important; &lt;!-- \u81ea\u5b9a\u4e49\u60ac\u6d6e\u989c\u8272 --&gt;\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ol>\n<li><strong>\u5224\u65ad\u662f\u5426\u89e6\u53d1\u5408\u5e76\u884c\u9ad8\u4eae\u903b\u8f91\uff1a<\/strong><\/li>\n<\/ol>\n<pre>expandchange(row) {\n  const { rowkey } = this.props;\n  \/\/ \u6269\u5c55\u884c\u65f6\uff0c\u89e6\u53d1\u6240\u6709\u5b50\u884c\u9ad8\u4eae\n  if (row.expanded) {\n    this.hoverrowkeyset.add(row[rowkey]);\n    this.expendedmap[row[rowkey]] = row;\n  \/\/ \u6536\u7f29\u884c\u65f6\uff0c\u79fb\u9664\u5b50\u884c\u9ad8\u4eae\n  } else {\n    const expandedrow = this.expendedmap[row[rowkey]];\n    const subrows = expandedrow.children || expandedrow._children;\n    subrows.foreach((subrow) =&gt; {\n      this.hoverrowkeyset.delete(subrow[rowkey]);\n      this.expendedmap[row[rowkey]] = undefined;\n    });\n  }\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ol>\n<li><strong>\u4fee\u6539\u60ac\u6d6e\u903b\u8f91\uff1a<\/strong><\/li>\n<\/ol>\n<pre>rowHover(mouseIn, row, el) {\n  const { rowKey } = this.props;\n  \/\/ \u6269\u5c55\u884c\u540e\uff0c\u6240\u6709\u5b50\u884c\u90fd\u4f1a\u89e6\u53d1\u7236\u884c\u60ac\u6d6e\n  if (this.expendedMap[row[rowKey]]) {\n    this.hoverRowKeySet.add(this.expendedMap[row[rowKey]][rowKey]);\n  \/\/ \u975e\u6269\u5c55\u884c\uff0c\u76f4\u63a5\u5224\u65ad\u5f53\u524d\u884c\u662f\u5426\u60ac\u6d6e\n  } else {\n    mouseIn ? this.hoverRowKeySet.add(row[rowKey]) : this.hoverRowKeySet.delete(row[rowKey]);\n  }\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u8fd9\u6837\u4fee\u6539\u540e\uff0c\u5c31\u53ef\u4ee5\u5b9e\u73b0\u6548\u679c 1 \u548c 2\uff0c\u9ad8\u4eae\u903b\u8f91\u548c\u6837\u5f0f\u90fd\u5f97\u5230\u4e86\u4f18\u5316\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u81ea\u5b9a\u4e49 el-table \u5408\u5e76\u884c\u60ac\u6d6e\u6837\u5f0f\u548c\u903b\u8f91\uff0c\u5b9e\u73b0\u9f20\u6807\u60ac\u505c\u6548\u679c\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>\u5982\u4f55\u81ea\u5b9a\u4e49 el-table \u5408\u5e76\u884c\u60ac\u6d6e\u6837\u5f0f\u548c\u903b\u8f91\uff1f \u5728\u7ebf demo \u7684\u6548\u679c\u4e2d\uff1a \u6548\u679c 1\uff1a\u9f20\u6807\u60ac\u505c\u5728\u7b2c\u4e00\u884c\u65f6\uff0c\u53ea\u9ad8\u4eae\u53f3\u4fa7\uff08\u6216\u6240\u6709\u884c\u9ad8\u4eae\u5408\u5e76\u884c\uff09\u3002 \u6548\u679c 2\uff1a\u9f20\u6807\u60ac\u505c\u5728\u5408\u5e76\u884c\u65f6\uff0c\u89e6\u53d1\u6240\u6709\u884c\u9ad8\u4eae\u3002 \u5982\u4f55\u5b9e\u73b0\uff1a \u8981\u5b9e\u73b0\u4e0a\u8ff0\u6548\u679c\uff0c\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u4fee\u6539\u4ee3\u7801\uff1a \u4fee\u6539\u60ac\u6d6e\u6837\u5f0f\uff1a .el-table__row.expanded { background-color: #f5f7fa!important; &lt;!&#8211; \u81ea\u5b9a\u4e49\u60ac\u6d6e\u989c\u8272 &#8211;&gt; } \u767b\u5f55\u540e\u590d\u5236 \u5224\u65ad\u662f\u5426\u89e6\u53d1\u5408\u5e76\u884c\u9ad8\u4eae\u903b\u8f91\uff1a expandchange(row) { const { rowkey } = this.props; \/\/ \u6269\u5c55\u884c\u65f6\uff0c\u89e6\u53d1\u6240\u6709\u5b50\u884c\u9ad8\u4eae if (row.expanded) { this.hoverrowkeyset.add(row[rowkey]); this.expendedmap[row[rowkey]] = row; \/\/ \u6536\u7f29\u884c\u65f6\uff0c\u79fb\u9664\u5b50\u884c\u9ad8\u4eae } else { const expandedrow = this.expendedmap[row[rowkey]]; const subrows = expandedrow.children || expandedrow._children; [&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-3021","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3021","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=3021"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3021\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=3021"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=3021"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=3021"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}