当我们需要清空 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 名称,
在Vue应用中,当需要清除el-table组件的选中记录时,可以使用内置的clearSelection函数。如果el-table在同一vue文件内,直接调用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名称。

1114

被折叠的 条评论
为什么被折叠?



