今天在使用elementUi中发现一个神奇的现象
当使用tabled的时候
使用一个table
<el-table ref="table"></el-table>
此时 尝试去打印 this.$refs.table 可以发现
此时比如我们嗲用 this.$refs.table.clearSelection()是可以调用的
但是当我们有多个table
<el-table ref="table1"></el-table>
<el-table ref="table2"></el-table>
打印 this.$refs.table1 this.$refs.table2 是这样的
此时我们调用 this.$refs.table1.clearSelection()
this.$refs.table2.clearSelection()是报错的
调用方式变为 this.$refs.table1[0].clearSelection()
this.$refs.table2[0].clearSelection()
我想问一下大佬们 为什么在多个table存在的时候 会产生这样的变化 this.$refs.table会由对象变化为数组对象
当在
v-for
里面的时候,会变成数组