el-table 中 @selection-change="handleSelectionChange" 是什么
时间: 2024-05-13 12:20:00 浏览: 37
`@selection-change` 是 Element UI 中 `<el-table>` 组件的一个事件,表示当表格中的选中项发生变化时会触发该事件。一般情况下,我们使用该事件来监听表格中选中的数据,以便进行后续的操作,例如删除、导出等。
`handleSelectionChange` 是一个自定义的方法名,表示当 `@selection-change` 事件触发时,所要执行的方法。在该方法中,我们可以通过 `$event` 参数来获取当前选中的数据,例如:
```html
<template>
<el-table :data="tableData" @selection-change="handleSelectionChange">
<el-table-column type="selection"></el-table-column>
<el-table-column prop="name" label="姓名"></el-table-column>
<el-table-column prop="age" label="年龄"></el-table-column>
</el-table>
</template>
<script>
export default {
data() {
return {
tableData: [
{ name: '张三', age: 18 },
{ name: '李四', age: 22 },
{ name: '王五', age: 30 }
],
selectedRows: [] // 用于存放选中的数据
}
},
methods: {
handleSelectionChange(selection) {
this.selectedRows = selection
}
}
}
</script>
```
在上面的例子中,我们通过 `@selection-change="handleSelectionChange"` 来监听表格中的选中数据变化,当数据发生变化时会触发 `handleSelectionChange` 方法,将选中的数据存放在 `selectedRows` 中。
相关推荐
![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)
![](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)