vue项目element嵌套表格的Drawer多选,报错TypeError: Cannot read property ‘toggleRowSelection‘ of undefined问题

	在做Drawer嵌套table并默认选中功能时,打开Drawer后发现table的ref操作报错Cannot read property 'toggleRowSelection' of undefined,感觉触发Drawer显示执行table选中逻辑但由于DOM并没有更新完,所以打印this.$refs为空,总结了两种解决办法。

//Drawer打开的Events

//showDrawer() {
//后台接口获取接口以及处理选中行的处理
     // this.table = true;
     // this.toggleSelection([this.tableData[1], this.tableData[2]]);//选中事件调用
  //  },
1toggleSelection(rows) {
      let _this =this    
      if (rows) {
        rows.forEach((row) => {         
       //先用延时器简单验证一下,也能实现效果
       setTimeout(function () {           
            _this.$refs.multipleTable.toggleRowSelection(row);
          },100)      
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },    
   **2**toggleSelection(rows) {   
      if (rows) {
        rows.forEach((row) => {         
           this.$nextTick().then(function () {
             _this.$refs.multipleTable.toggleRowSelection(row);
           })      
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },
    **//注:Drawer绑定要关闭事件,否则关闭后再打开Drawer后table选中会有问题**
    isclose(){
      //console.log('你清空了选中')
      this.$refs.multipleTable.clearSelection();//清空table的选中
    },
分享快乐,哈哈
  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值