toggleRowSelection(row, selected)接受两个参数,row传递被勾选行的数据,selected设置是否选中

注意:调用toggleRowSelection这个方法 需要获取真实dom 所以需要注册 ref 来引用它 

相关操作:

(一).默认选中

1.当数据源固定在table的

<script>
export default {   
    mounted() {
         this.$refs.multipleTable.toggleRowSelection(this.tableData3[2],true);
    }
}
</script>

(二).点击tr选中

1.在table中设置 @row-click="handleCurrentChange"

<template>
    <el-table :data="tableData3"  ref="multipleTable" @row-click="handleCurrentChange"></el-table>
</template>

<script>
export default { 
    methods: {
        handleCurrentChange(row, event, column){
            this.$refs.multipleTable.toggleRowSelection(row,true);//点击选中
        }
    }
}
</script>

(三).获取选中的值

1.设置table 中@selection-change="selsChange"

2.data 中设置sels:[]

<template>
<el-table :data="tableData3"  ref="multipleTable" @row-click="handleCurrentChange" @selection-change="selsChange"></el-table>
</template>

<script>
export default {
    methods: {
        selsChange( val){
            this.sels=val;
            console.log(this.sels)
        }
    }
}
</script>

转载自:https://www.cnblogs.com/hyhyhy/articles/10458095.html

GitHub 加速计划 / eleme / element
10
1
下载
A Vue.js 2.0 UI Toolkit for Web
最近提交(Master分支:5 个月前 )
c345bb45 9 个月前
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 9 个月前
Logo

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

更多推荐