{"id":25590,"date":"2024-11-24T08:37:53","date_gmt":"2024-11-24T00:37:53","guid":{"rendered":"https:\/\/fwq.ai\/blog\/25590\/"},"modified":"2024-11-24T08:37:53","modified_gmt":"2024-11-24T00:37:53","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8-element-ui-%e7%9a%84-el-col-%e4%b8%ad%ef%bc%8c%e8%ae%a9%e5%85%83%e7%b4%a0%e5%9c%a8%e8%b6%85%e8%bf%87-24-%e6%a0%bc%e6%97%b6%e4%bb%8d%e4%bf%9d%e6%8c%81%e5%9c%a8%e4%b8%80-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/25590\/","title":{"rendered":"\u5982\u4f55\u5728 Element UI \u7684 el-col \u4e2d\uff0c\u8ba9\u5143\u7d20\u5728\u8d85\u8fc7 24 \u683c\u65f6\u4ecd\u4fdd\u6301\u5728\u4e00\u884c\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173063686458948.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u5728 Element UI \u7684 el-col \u4e2d\uff0c\u8ba9\u5143\u7d20\u5728\u8d85\u8fc7 24 \u683c\u65f6\u4ecd\u4fdd\u6301\u5728\u4e00\u884c\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u5728 Element UI \u7684 el-col \u4e2d\uff0c\u8ba9\u5143\u7d20\u5728\u8d85\u8fc7 24 \u683c\u65f6\u4ecd\u4fdd\u6301\u5728\u4e00\u884c\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5728 element ui el-col \u4e2d\u8ba9\u5143\u7d20\u5728\u8d85\u8fc7 24 \u683c\u65f6\u4ecd\u4fdd\u6301\u5728\u4e00\u884c\uff1f<\/strong><\/p>\n<p>Element UI \u7684 el-col \u7ec4\u4ef6\u9650\u5236\u603b\u8de8\u5ea6\uff08span\uff09\u4e3a 24\u3002\u82e5\u8d85\u8fc7\u8fd9\u4e2a\u9650\u5236\uff0c\u5143\u7d20\u4f1a\u81ea\u52a8\u6362\u884c\u3002\u4e0d\u8fc7\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u81ea\u5b9a\u4e49\u5b9e\u73b0\uff0c\u8ba9\u5143\u7d20\u5728\u8d85\u8fc7 24 \u683c\u65f6\u4e5f\u4fdd\u6301\u5728\u4e00\u884c\u4e2d\u3002<\/p>\n<p><strong>\u81ea\u5b9a\u4e49\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n<p>\u5b9e\u73b0\u6b64\u529f\u80fd\u9700\u8981\u81ea\u5b9a\u4e49 CSS \u6837\u5f0f\u548c JavaScript \u5904\u7406\u3002<\/p>\n<p><strong>1. CSS \u6837\u5f0f\uff1a<\/strong><\/p>\n<pre>.el-row--custom {\n  display: flex;\n  flex-direction: row;\n  flex-wrap: nowrap;\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u4e2a\u6837\u5f0f\u53d6\u6d88\u4e86 el-row \u7684\u9ed8\u8ba4\u6362\u884c\u529f\u80fd\uff0c\u5f3a\u5236\u6240\u6709\u5143\u7d20\u5728\u4e00\u884c\u4e2d\u3002<\/p>\n<p><strong>2. JavaScript \u5904\u7406\uff1a<\/strong><\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u5728\u7ec4\u4ef6\u6302\u8f7d\u540e\uff0c\u4f7f\u7528 JavaScript \u8ba1\u7b97\u5143\u7d20\u7684\u5bbd\u5ea6\u3002\u5982\u679c\u603b\u5bbd\u5ea6\u8d85\u8fc7\u5bb9\u5668\u5bbd\u5ea6\uff08\u5047\u8bbe\u4e3a 960px\uff09\uff0c\u5219\u5c06 el-row \u7ec4\u4ef6\u81ea\u5b9a\u4e49\u6837\u5f0f\u7c7b\u540d\u6dfb\u52a0\u5230\u5bb9\u5668\u4e0a\u3002<\/p>\n<pre>mounted() {\n  const containerWidth = 960;\n  let totalWidth = 0;\n  this.$nextTick(() =&gt; {\n    const children = this.$el.children;\n    for (let i = 0; i &lt; children.length; i++) {\n      totalWidth += children[i].offsetWidth;\n    }\n    if (totalWidth &gt; containerWidth) {\n      this.$el.classList.add('el-row--custom');\n    }\n  });\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u5e94\u7528\u81ea\u5b9a\u4e49\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n<p>\u5728 Vue \u7ec4\u4ef6\u4e2d\uff0c\u5c06 el-row \u7ec4\u4ef6\u66ff\u6362\u4e3a\u5177\u6709\u81ea\u5b9a\u4e49\u6837\u5f0f\u7c7b\u7684\u81ea\u5b9a\u4e49\u7ec4\u4ef6\u3002<\/p>\n<pre>&lt;template&gt;\n  &lt;div&gt;\n    &lt;custom-row :gutter=\"12\"&gt;\n      &lt;el-col :span=\"8\"&gt;...&lt;\/el-col&gt;\n      &lt;el-col :span=\"8\"&gt;...&lt;\/el-col&gt;\n      ...\n    &lt;\/custom-row&gt;\n  &lt;\/div&gt;\n&lt;\/template&gt;\n\n&lt;script&gt;\nimport { defineComponent } from 'vue';\n\nexport default defineComponent({\n  components: {\n    customRow: {\n      template: '&lt;el-row class=\"el-row--custom\" :gutter=\"gutter\"&gt;'\n    }\n  },\n  props: {\n    gutter: {\n      type: Number,\n      default: 12\n    }\n  },\n  mounted() {\n    \/\/ ...\n  }\n});\n&lt;\/script&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong>\u6b64\u89e3\u51b3\u65b9\u6848\u4ec5\u9002\u7528\u4e8e flex \u5e03\u5c40\u652f\u6301\u7684\u6d4f\u89c8\u5668\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u5728 Element UI \u7684 el-col \u4e2d\uff0c\u8ba9\u5143\u7d20\u5728\u8d85\u8fc7 24 \u683c\u65f6\u4ecd\u4fdd\u6301\u5728\u4e00\u884c\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\u5728 element ui el-col \u4e2d\u8ba9\u5143\u7d20\u5728\u8d85\u8fc7 24 \u683c\u65f6\u4ecd\u4fdd\u6301\u5728\u4e00\u884c\uff1f Element UI \u7684 el-col \u7ec4\u4ef6\u9650\u5236\u603b\u8de8\u5ea6\uff08span\uff09\u4e3a 24\u3002\u82e5\u8d85\u8fc7\u8fd9\u4e2a\u9650\u5236\uff0c\u5143\u7d20\u4f1a\u81ea\u52a8\u6362\u884c\u3002\u4e0d\u8fc7\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u81ea\u5b9a\u4e49\u5b9e\u73b0\uff0c\u8ba9\u5143\u7d20\u5728\u8d85\u8fc7 24 \u683c\u65f6\u4e5f\u4fdd\u6301\u5728\u4e00\u884c\u4e2d\u3002 \u81ea\u5b9a\u4e49\u89e3\u51b3\u65b9\u6848\uff1a \u5b9e\u73b0\u6b64\u529f\u80fd\u9700\u8981\u81ea\u5b9a\u4e49 CSS \u6837\u5f0f\u548c JavaScript \u5904\u7406\u3002 1. CSS \u6837\u5f0f\uff1a .el-row&#8211;custom { display: flex; flex-direction: row; flex-wrap: nowrap; } \u767b\u5f55\u540e\u590d\u5236 \u8fd9\u4e2a\u6837\u5f0f\u53d6\u6d88\u4e86 el-row \u7684\u9ed8\u8ba4\u6362\u884c\u529f\u80fd\uff0c\u5f3a\u5236\u6240\u6709\u5143\u7d20\u5728\u4e00\u884c\u4e2d\u3002 2. JavaScript \u5904\u7406\uff1a \u6211\u4eec\u53ef\u4ee5\u5728\u7ec4\u4ef6\u6302\u8f7d\u540e\uff0c\u4f7f\u7528 JavaScript \u8ba1\u7b97\u5143\u7d20\u7684\u5bbd\u5ea6\u3002\u5982\u679c\u603b\u5bbd\u5ea6\u8d85\u8fc7\u5bb9\u5668\u5bbd\u5ea6\uff08\u5047\u8bbe\u4e3a 960px\uff09\uff0c\u5219\u5c06 el-row \u7ec4\u4ef6\u81ea\u5b9a\u4e49\u6837\u5f0f\u7c7b\u540d\u6dfb\u52a0\u5230\u5bb9\u5668\u4e0a\u3002 mounted() { const containerWidth = 960; let totalWidth = [&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-25590","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25590","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=25590"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25590\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=25590"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=25590"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=25590"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}