el-table设置默认选中报错_this.$refs.singleTable.toggleAllSelection is not a function

直接使用以下的方法,报错信息是`_this.$refs.singleTable.toggleAllSelection is not a function

bash 复制代码
this.$refs.singleTable.toggleAllSelection()

看了网上的解决方法,加了this.$nextTick,代码如下,但还是报错Error in nextTick: "TypeError: _this.$refs.singleTable.toggleAllSelection is not a function"

bash 复制代码
_this.$nextTick(() => {
    _this.$refs.singleTable.toggleAllSelection()
})

报错信息是this.$refs.singleTable.toggleAllSelection这个东西不存在或者有错误,所以我决定把this.$refs.singleTable打印出来看看是什么东西!

bash 复制代码
console.log(this.$refs.singleTable);

打印出来了是这么一个东西,看他的格式应该是类似数组

再把它展开,终于在中间部分找到了这个方法,所以这个方法并不是直接this.$refs.singleTable调用,而是在this.$refs.singleTable[0]里面


解决办法:

bash 复制代码
this.$refs.singleTable改成this.$refs.singleTable[0]解决

代码:

bash 复制代码
this.$nextTick(() => {
     this.$refs.singleTable[0].toggleAllSelection()
})
相关推荐
星栈43 分钟前
pnpm 12 升级实测
前端·javascript
Sirens.1 小时前
Java并发锁详解:六类锁策略与 synchronized 底层原理
java·前端·算法
特创数字科技2 小时前
一个纯本地运行的图片处理工具:压缩 / 裁剪 / 九宫格 / 圆角 / 滤镜 / 拼图 / 水印,终生使用
前端
IT_陈寒3 小时前
Vue的v-if和v-for混用居然是个天坑
前端·人工智能·后端
天衍四九-3 小时前
【无标题】
前端·spring boot·mysql·nginx·docker
广州华水科技3 小时前
2026年单北斗GNSS变形监测系统推荐榜单,解锁GNSS位移监测新高度
前端
xcyxiner3 小时前
DicomViewer24 修复编译bug(window test 失败)
前端·qt
linux_cfan4 小时前
videojs v10 源代码系列解读:34 · `createComposition`:类型安全的冲突检测
前端·安全
utmhikari5 小时前
【AI原生】借助AI之力优化个人博客前端样式
前端·css·hexo·next·个人博客·ai-native·vibe coding