element ui 表格 :width
时间: 2023-08-28 07:16:17 浏览: 177
根据引用中提供的信息,Element UI的表格组件可以通过遍历tableData和表头来找出每一列中最长的字符,并根据该最长字符计算出最小宽度。具体的步骤如下:
1. 使用遍历方法遍历tableData和表头,找出每一列中的最长字符。
2. 创建一个span标签用于计算最长字符所占的宽度,通过offsetWidth属性获取到该宽度。
3. 将获取到的最长字符的宽度设置为列的min-width属性,这样可以确保表格在渲染过程中宽度和高度的稳定性。
4. 在组件渲染前计算出最小宽度,避免表格渲染过程中宽度高度不稳定的情况。
根据你提供的代码示例,可以看出设置了每一列的宽度为"50px",这种情况下宽度不会自动计算。如果希望实现自动计算宽度,需要将width属性设为"auto"或不设置宽度属性,默
相关问题
element ui表格抖动
element ui表格抖动的原因是因为无论是显示列还是隐藏列,vue都需要重新计算单元格的高度和宽度,然后再重新渲染到页面上。因为这个过程被直接反馈到了页面上,所以导致了table发生闪烁。解决方法是使用element中的dolayout函数。具体实现方法如下:
```javascript
<template>
<el-table
:data="tableData"
style="width: 100%"
:key="tableKey"
ref="table"
@selection-change="handleSelectionChange"
@sort-change="handleSortChange"
@filter-change="handleFilterChange"
@row-click="handleRowClick"
@row-dblclick="handleRowDblclick"
@row-contextmenu="handleRowContextmenu"
@header-click="handleHeaderClick"
@header-contextmenu="handleHeaderContextmenu"
@current-change="handleCurrentChange"
@header-dragend="handleHeaderDragend"
@expand-change="handleExpandChange"
@select="handleSelect"
@select-all="handleSelectAll"
@cell-mouse-enter="handleCellMouseEnter"
@cell-mouse-leave="handleCellMouseLeave"
@cell-click="handleCellClick"
@cell-dblclick="handleCellDblclick"
@cell-contextmenu="handleCellContextmenu"
@edit-disabled="handleEditDisabled"
@edit-closed="handleEditClosed"
@edit-actived="handleEditActived"
@edit-canceled="handleEditCanceled"
@edit-submit="handleEditSubmit"
@edit-command="handleEditCommand"
@edit-queue-full="handleEditQueueFull"
@edit-clear="handleEditClear"
@edit-validate="handleEditValidate"
@edit-invalid="handleEditInvalid"
@edit-valid="handleEditValid"
@edit-error="handleEditError"
@edit-reset="handleEditReset"
@edit-render="handleEditRender"
@edit-parse-value="handleEditParseValue"
@edit-format-value="handleEditFormatValue"
@edit-select-all="handleEditSelectAll"
@edit-tab="handleEditTab"
@edit-toggle-dropdown="handleEditToggleDropdown"
@edit-click="handleEditClick"
@edit-focus="handleEditFocus"
@edit-blur="handleEditBlur"
@edit-change="handleEditChange"
@edit-input="handleEditInput"
@edit-composition-start="handleEditCompositionStart"
@edit-composition-update="handleEditCompositionUpdate"
@edit-composition-end="handleEditCompositionEnd"
@edit-custom-command="handleEditCustomCommand"
@edit-custom-button-click="handleEditCustomButtonClick"
@edit-custom-cell-click="handleEditCustomCellClick"
@edit-custom-cell-mouseenter="handleEditCustomCellMouseenter"
@edit-custom-cell-mouseleave="handleEditCustomCellMouseleave"
@edit-custom-cell-contextmenu="handleEditCustomCellContextmenu"
@edit-custom-cell-dblclick="handleEditCustomCellDblclick"
@edit-custom-cell-focus="handleEditCustomCellFocus"
@edit-custom-cell-blur="handleEditCustomCellBlur"
@edit-custom-cell-keydown="handleEditCustomCellKeydown"
@edit-custom-cell-keyup="handleEditCustomCellKeyup"
@edit-custom-cell-keypress="handleEditCustomCellKeypress"
@edit-custom-cell-edit-disabled="handleEditCustomCellEditDisabled"
@edit-custom-cell-edit-closed="handleEditCustomCellEditClosed"
@edit-custom-cell-edit-actived="handleEditCustomCellEditActived"
@edit-custom-cell-edit-canceled="handleEditCustomCellEditCanceled"
@edit-custom-cell-edit-submit="handleEditCustomCellEditSubmit"
@edit-custom-cell-edit-command="handleEditCustomCellEditCommand"
@edit-custom-cell-edit-queue-full="handleEditCustomCellEditQueueFull"
@edit-custom-cell-edit-clear="handleEditCustomCellEditClear"
@edit-custom-cell-edit-validate="handleEditCustomCellEditValidate"
@edit-custom-cell-edit-invalid="handleEditCustomCellEditInvalid"
@edit-custom-cell-edit-valid="handleEditCustomCellEditValid"
@edit-custom-cell-edit-error="handleEditCustomCellEditError"
@edit-custom-cell-edit-reset="handleEditCustomCellEditReset"
@edit-custom-cell-edit-render="handleEditCustomCellEditRender"
@edit-custom-cell-edit-parse-value="handleEditCustomCellEditParseValue"
@edit-custom-cell-edit-format-value="handleEditCustomCellEditFormatValue"
@edit-custom-cell-edit-select-all="handleEditCustomCellEditSelectAll"
@edit-custom-cell-edit-tab="handleEditCustomCellEditTab"
@edit-custom-cell-edit-toggle-dropdown="handleEditCustomCellEditToggleDropdown"
@edit-custom-cell-edit-click="handleEditCustomCellEditClick"
@edit-custom-cell-edit-focus="handleEditCustomCellEditFocus"
@edit-custom-cell-edit-blur="handleEditCustomCellEditBlur"
@edit-custom-cell-edit-change="handleEditCustomCellEditChange"
@edit-custom-cell-edit-input="handleEditCustomCellEditInput"
@edit-custom-cell-edit-composition-start="handleEditCustomCellEditCompositionStart"
@edit-custom-cell-edit-composition-update="handleEditCustomCellEditCompositionUpdate"
@edit-custom-cell-edit-composition-end="handleEditCustomCellEditCompositionEnd"
@edit-custom-cell-edit-custom-command="handleEditCustomCellEditCustomCommand"
@edit-custom-cell-edit-custom-button-click="handleEditCustomCellEditCustomButtonClick"
@edit-custom-cell-edit-custom-cell-click="handleEditCustomCellEditCustomCellClick"
@edit-custom-cell-edit-custom-cell-mouseenter="handleEditCustomCellEditCustomCellMouseenter"
@edit-custom-cell-edit-custom-cell-mouseleave="handleEditCustomCellEditCustomCellMouseleave"
@edit-custom-cell-edit-custom-cell-contextmenu="handleEditCustomCellEditCustomCellContextmenu"
@edit-custom-cell-edit-custom-cell-dblclick="handleEditCustomCellEditCustomCellDblclick"
@edit-custom-cell-edit-custom-cell-focus="handleEditCustomCellEditCustomCellFocus"
@edit-custom-cell-edit-custom-cell-blur="handleEditCustomCellEditCustomCellBlur"
@edit-custom-cell-edit-custom-cell-keydown="handleEditCustomCellEditCustomCellKeydown"
@edit-custom-cell-edit-custom-cell-keyup="handleEditCustomCellEditCustomCellKeyup"
@edit-custom-cell-edit-custom-cell-keypress="handleEditCustomCellEditCustomCellKeypress"
@edit-custom-cell-edit-custom-cell-edit-disabled="handleEditCustomCellEditCustomCellEditDisabled"
@edit-custom-cell-edit-custom-cell-edit-closed="handleEditCustomCellEditCustomCellEditClosed"
@edit-custom-cell-edit-custom-cell-edit-actived="handleEditCustomCellEditCustomCellEditActived"
@edit-custom-cell-edit-custom-cell-edit-canceled="handleEditCustomCellEditCustomCellEditCanceled"
@edit-custom-cell-edit-custom-cell-edit-submit="handleEditCustomCellEditCustomCellEditSubmit"
@edit-custom-cell-edit-custom-cell-edit-command="handleEditCustomCellEditCustomCellEditCommand"
@edit-custom-cell-edit-custom-cell-edit-queue-full="handleEditCustomCellEditCustomCellEditQueueFull"
@edit-custom-cell-edit-custom-cell-edit-clear="handleEditCustomCellEditCustomCellEditClear"
@edit-custom-cell-edit-custom-cell-edit-validate="handleEditCustomCellEditCustomCellEditValidate"
@edit-custom-cell-edit-custom-cell-edit-invalid="handleEditCustomCellEditCustomCellEditInvalid"
@edit-custom-cell-edit-custom-cell-edit-valid="handleEditCustomCellEditCustomCellEditValid"
@edit-custom-cell-edit-custom-cell-edit-error="handleEditCustomCellEditCustomCellEditError"
@edit-custom-cell-edit-custom-cell-edit-reset="handleEditCustomCellEditCustomCellEditReset"
@edit-custom-cell-edit-custom-cell-edit-render="handleEditCustomCellEditCustomCellEditRender"
@edit-custom-cell-edit-custom-cell-edit-parse-value="handleEditCustomCellEditCustomCellEditParseValue"
@edit-custom-cell-edit-custom-cell-edit-format-value="handleEditCustomCellEditCustomCellEditFormatValue"
@edit-custom-cell-edit-custom-cell-edit-select-all="handleEditCustomCellEditCustomCellEditSelectAll"
@edit-custom-cell-edit-custom-cell-edit-tab="handleEditCustomCellEditCustomCellEditTab"
@edit-custom-cell-edit-custom-cell-edit-toggle-dropdown="handleEditCustomCellEditCustomCellEditToggleDropdown"
@edit-custom-cell-edit-custom-cell-edit-click="handleEditCustomCellEditCustomCellEditClick"
@edit-custom-cell-edit-custom-cell-edit-focus="handleEditCustomCellEditCustomCellEditFocus"
@edit-custom-cell-edit-custom-cell-edit-blur="handleEditCustomCellEditCustomCellEditBlur"
@edit-custom-cell-edit-custom-cell-edit-change="handleEditCustomCellEditCustomCellEditChange"
@edit-custom-cell-edit-custom-cell-edit-input="handleEditCustomCellEditCustomCellEditInput"
@edit-custom-cell-edit-custom-cell-edit-composition-start="handleEditCustomCellEditCustomCellEditCompositionStart"
@edit-custom-cell-edit-custom-cell-edit-composition-update="handleEditCustomCellEditCustomCellEditCompositionUpdate"
@edit-custom-cell-edit-custom-cell-edit-composition-end="handleEditCustomCellEditCustomCellEditCompositionEnd"
@edit-custom-cell-edit-custom-cell-edit-custom-command="handleEditCustomCellEditCustomCellEditCustomCommand"
@edit-custom-cell-edit-custom-cell-edit-custom-button-click="handleEditCustomCellEditCustomCellEditCustomButtonClick"
@edit-custom-cell-edit-custom-cell-edit-custom-cell-click="handleEditCustomCellEditCustomCellEditCustomCellClick"
@edit-custom-cell-edit-custom-cell-edit-custom-cell-mouseenter="handleEditCustomCellEditCustomCellEditCustomCellMouseenter"
@edit-custom-cell-edit-custom-cell-edit-custom-cell-mouseleave="handleEditCustomCellEditCustomCellEditCustomCellMouseleave"
@edit-custom-cell-edit-custom-cell-edit-custom-cell-contextmenu="handleEditCustomCellEditCustomCellEditCustomCellContextmenu"
@edit-custom-cell-edit-custom-cell-edit-custom-cell-dblclick="handleEditCustomCellEditCustomCellEditCustomCellDblclick"
@edit-custom-cell-edit-custom-cell-edit-custom-cell-focus="handleEditCustomCellEditCustomCellEditCustomCellFocus"
@edit-custom-cell-edit-custom-cell-edit-custom-cell-blur="handleEditCustomCellEditCustomCellEditCustomCellBlur"
@edit-custom-cell-edit-custom-cell-edit-custom-cell-keydown="handleEditCustomCellEditCustomCellEditCustomCellKeydown"
@edit-custom-cell-edit-custom-cell-edit-custom-cell-keyup="handleEditCustomCellEditCustomCellEditCustomCellKeyup"
@edit-custom-cell-edit-custom-cell-edit-custom-cell-keypress="handleEditCustomCellEditCustomCellEditCustomCellKeypress"
@edit-custom-cell-edit-custom-cell-edit-custom-cell-edit-disabled="handleEditCustomCellEditCustomCellEditCustomCellEditDisabled"
@edit-custom-cell-edit-custom-cell-edit-custom-cell-edit-closed="handleEditCustomCellEditCustomCellEditCustomCellEditClosed"
@edit-custom-cell-edit-custom-cell-edit-custom-cell-edit-actived="handleEditCustomCellEditCustomCellEditCustomCellEditActived"
@edit-custom-cell-edit-custom-cell-edit-custom-cell-edit-canceled="handleEditCustomCellEditCustomCellEditCustomCellEditCanceled"
@edit-custom-cell-edit-custom-cell-edit-custom-cell-edit-submit="handleEditCustomCellEditCustomCellEditCustomCellEditSubmit"
@edit-custom-cell-edit-custom-cell-edit-custom-cell-edit-command="handleEditCustomCellEditCustomCellEditCustomCellEditCommand"
@edit-custom-cell-edit-custom-cell-edit-custom-cell-edit-queue-full="handleEditCustomCellEditCustomCellEditCustomCellEditQueueFull"
@edit-custom-cell-edit-custom-cell-edit-custom-cell-edit-clear="handleEditCustomCellEditCustomCellEditCustomCellEditClear"
@edit-custom-cell-edit-custom-cell-edit-custom-cell-edit-validate="handleEditCustomCellEditCustomCellEditCustomCellEditValidate"
@edit-custom-cell-edit-custom-cell-edit-custom-cell-edit-invalid="handleEditCustomCellEditCustomCellEditCustomCellEditInvalid"
@edit-custom-cell-edit-custom-cell-edit-custom-cell-edit-valid="handleEditCustomCellEditCustomCellEditCustomCellEditValid"
@edit-custom-cell-edit-custom-cell-edit-custom-cell-edit-error="handleEditCustomCellEditCustomCellEditCustomCellEditError"
@edit-custom-cell-edit-custom-cell-edit-custom-cell-edit-reset="handleEditCustomCellEditCustomCellEditCustomCellEditReset"
@edit-custom-cell-edit-custom-cell-edit-custom-cell-edit-render="handleEditCustomCellEditCustomCellEditCustomCellEditRender"
@edit-custom-cell-edit-custom-cell-edit-custom-cell-edit-parse-value="handleEditCustomCellEditCustomCellEditCustomCellEditParseValue"
@edit-custom-cell-edit-custom-cell-edit-custom-cell-edit-format-value="handleEditCustomCellEditCustomCellEditCustomCellEditFormatValue"
@edit-custom-cell-edit-custom-cell-edit-custom-cell-edit-select-all="handleEditCustomCellEditCustomCellEditCustomCellEditSelectAll"
@edit-custom-cell-edit-custom-cell-edit-custom-cell-edit-tab="handleEditCustomCellEditCustomCellEditCustomCellEditTab"
@edit-custom-cell-edit-custom-cell-edit-custom-cell-edit-toggle-dropdown="handleEditCustomCellEditCustomCellEditCustomCellEditToggleDropdown"
@edit-custom-cell-edit-custom-cell-edit-custom-cell-edit-click="handleEditCustomCellEditCustomCellEditCustomCellEditClick"
@edit-custom-cell-edit-custom-cell-edit-custom-cell-edit-focus="handleEditCustomCellEditCustomCellEditCustomCellEditFocus"
@edit-custom-cell-edit-custom-cell-edit-custom-cell-edit-blur="handleEditCustomCellEditCustomCellEditCustomCellEditBlur"
@edit-custom-cell-edit-custom-cell-edit-custom-cell-edit-change="handleEditCustomCellEditCustomCellEditCustomCellEditChange"
@edit-custom-cell-edit-custom-cell-edit-custom-cell-edit-input="handleEditCustomCellEditCustomCellEditCustomCellEditInput"
@edit-custom-cell-edit-custom-cell-edit-custom-cell-edit-composition-start="handleEditCustomCellEditCustomCellEditCustomCellEditCompositionStart"
@edit-custom-cell-edit-custom-cell-edit-custom-cell-edit-composition
element ui表格宽度
您可以通过设置 `width` 属性来控制 Element UI 表格的宽度。具体方法如下:
1. 在 `<el-table>` 标签中添加 `width` 属性,例如:`<el-table :data="tableData" width="100%">`,这样表格的宽度就会被设置为父容器的 100%。
2. 如果您想设置表格的固定宽度,可以使用 `:style="{width: '固定宽度'}"` 来进行设置,例如:`<el-table :data="tableData" :style="{width: '500px'}">`,这样表格的宽度就会被设置为 500px。
另外,您还可以通过设置表格的 `min-width` 和 `max-width` 属性来控制表格的最小和最大宽度。例如:`<el-table :data="tableData" :style="{minWidth: '300px', maxWidth: '800px'}">`,这样表格的宽度就会在 300px 和 800px 之间变化。
阅读全文