uni-app uniCloud Admin 在微信小程序中分页时执行报错 Cannot read property 'clearSelection' of undefined

uni-app uniCloud Admin 在微信小程序中分页时执行报错 Cannot read property ‘clearSelection’ of undefined

示例代码:

pages/system/user/list 235行

onPageChanged(e) {  
    this.selectedIndexs.length = 0  
    this.$refs.table.clearSelection() //这里就会报错  
    this.$refs.udb.loadData({  
        current: e.current  
    })  
},

操作步骤:

unicloud admin 很多用户进行分页,点击下一页。

预期结果:

不报错,正常翻页

实际结果:

仅仅页数变了,但是实际上没有翻页。

bug描述:

在uni-starter的admin端,涉及this.$refs.table.clearSelection()的代码会报错。导致很多微信小程序无法分页面 TypeError: Cannot read property ‘clearSelection’ of undefined at VueComponent.<anonymous> (list.vue:178) at Array.<anonymous> (mp.runtime.esm.js?66fd:1984) at flushCallbacks (mp.runtime.esm.js?66fd:1912)(env: macOS,mp,1.05.2109131; lib: 2.15.0)

按照网上的手法,增加了nextTick,似乎还是有错误。 前端都这么复杂了啊,厉害,厉害啊。 再有个问题,这个修正之后,我如何获得修正后的更新啊。。。?直接暴力的覆盖过去的版本?还是说,需要使用时使用git的版本?还是说,这个是基于更底层的sdk,我不需要动就能获得更新? 因为我修改了代码,让其现在可以在线上运行,如果问题修复,我还需要将修复代码还原回来么?

PS:你们弄的这东东是个很棒的产品,让人很感兴趣。


| 开发环境 | 版本号   | 项目创建方式 |
|----------|----------|--------------|
| macOS    | mp,1.05.2109131 | lib: 2.15.0  |

![image](https://www.itying.com/uniimg.php?url=https://img-cdn-tc.dcloud.net.cn/uploads/questions/20211031/919cdcfd7ca77bc4ba392d2d99884315.png)
![image](https://www.itying.com/uniimg.php?url=https://img-cdn-tc.dcloud.net.cn/uploads/questions/20211031/0963a69364819b5b7255bf0a658d0bf7.png)

更多关于uni-app uniCloud Admin 在微信小程序中分页时执行报错 Cannot read property 'clearSelection' of undefined的实战教程也可以访问 https://www.itying.com/category-93-b0.html

2 回复

这个this.$refs.table.clearSelection()是阻断性bug,把这个干掉之后,程序运行正常了。但是上个页面选择的复选框,会带到下个页面去。 总之,先让程序正常吧。 还有个导出文件的bug需要处理,报错Cannot read property ‘btoa’ of undefined。我看到代码默认使用的是条件编译,支持H5的,这说明微信小程序可能是存在问题。如何处理呢。。。?

更多关于uni-app uniCloud Admin 在微信小程序中分页时执行报错 Cannot read property 'clearSelection' of undefined的实战教程也可以访问 https://www.itying.com/category-93-b0.html


这个错误是因为在微信小程序环境中,this.$refs.table 在分页切换时可能还未正确初始化或已销毁。clearSelection() 是 uni-table 组件的方法,但在某些情况下组件引用会丢失。

解决方案:

  1. 添加判空处理(推荐):
onPageChanged(e) {
    this.selectedIndexs.length = 0
    if (this.$refs.table && this.$refs.table.clearSelection) {
        this.$refs.table.clearSelection()
    }
    this.$refs.udb.loadData({
        current: e.current
    })
}
  1. 使用 nextTick 的正确方式
onPageChanged(e) {
    this.selectedIndexs.length = 0
    this.$nextTick(() => {
        if (this.$refs.table && this.$refs.table.clearSelection) {
            this.$refs.table.clearSelection()
        }
    })
    this.$refs.udb.loadData({
        current: e.current
    })
}
回到顶部