当前位置 博文首页 > this.$refs.singleTable.toggleRowSelection is not a function_
直接使用以下的方法,报错信息是_this.$refs.singleTable.toggleRowSelection is not a function
this.$refs.singleTable.toggleRowSelection(item, true)
?
看了网上的解决方法,加了this.$nextTick,代码如下,但还是报错Error in nextTick: "TypeError: _this.$refs.singleTable.toggleRowSelection is not a function"
_this.$nextTick(() => {
_this.$refs.singleTable.toggleRowSelection(item, true)
})
?
看报错信息是this.$refs.singleTable.toggleRowSelection这个东西不存在或者有错误,所以我决定把this.$refs.singleTable打印出来看看是什么东西!
console.log(this.$refs.singleTable);
打印出来了是这么一个东西,看他的格式应该是类似数组?
?
再把它展开,终于在中间部分找到了这个方法,所以这个方法并不是直接this.$refs.singleTable调用,而是在this.$refs.singleTable[0]里面
this.$refs.singleTable改成this.$refs.singleTable[0]解决
代码:
this.$nextTick(() => {
this.$refs.singleTable[0].toggleRowSelection(item, true)
})
说句话:这个代码似乎有点奇怪,但确实是解决问题了,就当做记录下这个解决问题的方法吧,遇到undefined问题就打印出来看看~
cs