当我们需要清空 el-table 的选中记录时,需要用到内置 clearSelection 函数,而他的用法需要分两种情况来说。一种是执行 clearSelection 这个操作的代码与 el-table 在同一 vue 文件中,另一种则是不在同一文件中,也就是 el-table 被封装在子组件中,供父组件调用。
情况一:el-table 在当前 vue 文件中
此时直接调用 el-table 的 clearSelection 函数即可:
this.$refs.myTable.clearSelection()
注:myTable 是 el-table 的 refs 名称
情况二:el-table 在 子组件中
此时有两种方法可用:
方法一:
this.$refs.tableComponent.$refs.commonTable.clearSelection()
方法二:
this.$refs.tableComponent.$children[0].clearSelection()
注:tableComponent 是子组件的 refs 名称,commonTable 是 el-table 的 refs 名称,