在做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的选中
    },
分享快乐,哈哈
GitHub 加速计划 / eleme / element
13
1
下载
A Vue.js 2.0 UI Toolkit for Web
最近提交(Master分支:1 个月前 )
c345bb45 1 年前
a07f3a59 * Update transition.md * Update table.md * Update transition.md * Update table.md * Update transition.md * Update table.md * Update table.md * Update transition.md * Update popover.md 1 年前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐