element ui 选择框多选
时间: 2023-08-12 15:08:41 浏览: 79
element-ui的多选框问题是指当设置多选框的min属性超过1时,无法选中第一项。根据提供的代码,可以看出问题出现在handleSelectionChange方法中的逻辑上。在这个方法中,当勾选项的数量为0时,会直接返回,导致无法选中第一项。
解决这个问题的方法是,在handleSelectionChange方法中,将清除所有勾选项的代码移动到if语句的外部,这样即使勾选项的数量为0,也能够选中第一项。修改后的代码如下:
```javascript
handleSelectionChange(selection, row) {
// 清除所有勾选项
this.$refs.multipleTable.clearSelection()
// 当表格数据都没有被勾选的时候就返回
// 主要用于将当前勾选的表格状态清除
if (selection.length === 0) return
this.multiple = !e.length
this.single = e.length !== 1
this.bill_id = row.id
this.$refs.multipleTable.toggleRowSelection(row, true)
}
```
这样修改后,多选框就能够正常选中第一项了。
相关问题
element ui 表单提交多选
对于element-ui的el-table表格复选框,可以通过使用selection-change事件来实现多选和单选的功能。具体的代码实现如下:
```html
<template>
<el-button type="success" icon="el-icon-first-aid-kit" :disabled="multiple">多选</el-button>
<el-button type="success" icon="el-icon-first-aid-kit" :disabled="single">单选</el-button>
<el-table ref="multipleTable" :data="tableData" border @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55"></el-table-column>
</el-table>
</template>
```
在上述代码中,@selection-change="handleSelectionChange"表示当选择发生改变时,会执行名为handleSelectionChange的方法。在该方法中,可以通过获取选中的数据进行相应的处理,如获取选中的多条数据或者获取选中的单条数据。
element ui表格内容禁止多选
要禁止Element UI表格的多选功能,可以通过在模板中的el-table组件上添加:row-selection="false"属性来实现。这样设置后,表格将不再显示选择框,也无法进行多选操作。\[1\]
例如,将模板中的el-table组件修改为以下代码:
```
<el-table ref="multipleTable" :data="tableData" border :row-selection="false">
<el-table-column type="selection" width="55"></el-table-column>
</el-table>
```
这样就禁止了Element UI表格的多选功能。
#### 引用[.reference_title]
- *1* *3* [element ui 表格单选 多选](https://blog.csdn.net/qq_35350009/article/details/125801525)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [Element UI 表格单选、多选情景](https://blog.csdn.net/weixin_42505381/article/details/128810420)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)