要想 table 出现多选操作列,只需要给 el-table 加一个 el-table-column ,并设 type 属性为 selection

<el-table>
	<el-table-column type="selection"></el-table-column>
</el-table>

多选示例

如果需要获取勾选了哪些行,需要给 el-table 加一个事件。

<el-table @selection-change="handleSelectionChange">
	<el-table-column type="selection"></el-table-column>
</el-table>
<script>
  export default {
    data() {
      return {
        multipleSelection: []
      }
    },
    methods: {
      handleSelectionChange(val) {
        this.multipleSelection = val;
      }
    }
  }
</script>

此时方法的 val 是选中的所有数据组成的数组,以下方法可以获取里面的某个字段。

methods: {
	handleSelectionChange(val) {
		// this.multipleSelection = val;
		this.multipleSelection = []
		// 假设取出 id 字段
		val.forEach(item => {
			const id = item.id
			// 判断数组中是否包含这个 id 
			if (this.multipleSelection.indexOf(id) == -1) {
				this.multipleSelection.push(id)
			}
		})
	}
}
GitHub 加速计划 / eleme / element
13
1
下载
A Vue.js 2.0 UI Toolkit for Web
最近提交(Master分支:30 天前 )
c345bb45 1 年前
a07f3a59 * Update transition.md * Update table.md * Update transition.md * Update table.md * Update transition.md * Update table.md * Update table.md * Update transition.md * Update popover.md 1 年前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐