外贸网站首页,公司建设内容,网站投票页面怎么做,wordpress爆路径1. 需求
在el-table中#xff0c;需要实现多选功能#xff0c;并且点击某一行的任意位置就勾选上#xff0c;而不是点击复选框才勾选上。
2. 实现思路
在el-table中添加ref属性#xff0c;用于获取表格实例。在el-table-column中添加typeselection属性…1. 需求
在el-table中需要实现多选功能并且点击某一行的任意位置就勾选上而不是点击复选框才勾选上。
2. 实现思路
在el-table中添加ref属性用于获取表格实例。在el-table-column中添加typeselection属性用于显示复选框。在el-table中添加row-clickhandleRowClick属性用于点击某一行的任意位置就获取到。在handleRowClick方法中通过toggleRowSelection方法来勾选或取消勾选当前行。
3. 代码实现
templateel-tablereftableRef:datatableDataselection-changehandleSelectionChangerow-clickhandleRowClickel-table-column typeselection width55/el-table-columnel-table-column propdate label日期 width180/el-table-columnel-table-column propname label姓名 width180/el-table-columnel-table-column propaddress label地址/el-table-column/el-table
/templatescript
import { ref, reactive } from vue
const tableRef ref(); // 获取表格实例
const state reactive({tableSelections: [] as any[],
})
/*** 表格多选*/
const handleSelectionChange (val: any) {state.tableSelections val// console.log(val, ---val)
}
!-- --
function handleRowClick(row: any) {// 判断当前行是否被选中const isSelected state.tableSelections.includes(row);// 如果当前行被选中则取消选中如果当前行未被选中则选中tableRef.value?.toggleRowSelection(row, !isSelected);
}
/script