vue 中如何同时让多个 table 切换选中状态

2019-01-28 19:59:16 +08:00
 Alerta

目前想要实现的功能是在页面加载完多个表格之后,将这几个表格全部默认全选。现在在每个 table 中都有设置好 ref

          <el-col :span="7">
            <el-card :body-style="{ padding: '0px' }">
              <el-table ref="cmpt_vip_table" :data="cmpt_case_data.AdVIPCase" :max-height=600
                        @selection-change="AdSelectionChange">
                <el-table-column type="selection" label="选择">
                </el-table-column>
                <el-table-column label="AdVIPCase" prop="case_name">
                </el-table-column>
              </el-table>
            </el-card>
          </el-col>

          <el-col :span="7">
            <el-card :body-style="{ padding: '0px' }">
              <el-table ref="cmpt_carousel_table" :data="cmpt_case_data.CarouselCase" :max-height=600
                        @selection-change="VipSelectionChange">
                <el-table-column type="selection" label="选择">
                </el-table-column>
                <el-table-column label="CarouselCase" prop="case_name">
                </el-table-column>
              </el-table>
            </el-card>
          </el-col>

然后再 created()中实现默认全选的逻辑

    created() {
      this.$axios.get(this.get_regression_case_url)
        .then(response => {
          this.regression_case_data = response.data;
          this.$refs.sup_table.toggleAllSelection();
          this.$refs.ad_table.toggleAllSelection();
          this.$refs.vip_table.toggleAllSelection();
          this.$refs.carousel_table.toggleAllSelection();
          this.$refs.vod_table.toggleAllSelection();
        })
        .catch(e => {
          this.errors.push(e)
        });
    },

但是实际上不能全部表格都全选,只有最后一个"vod_table"生效,且每次都是最后一个生效(有全选)

4333 次点击
所在节点    Vue.js
4 条回复
Alerta
2019-01-28 19:59:38 +08:00
求助各位 vue 大佬,求助求助
Alerta
2019-01-28 21:13:48 +08:00
DING
Alerta
2019-01-29 13:52:25 +08:00
顶一顶,希望有大佬看到
ghostheaven
2019-01-29 17:43:16 +08:00
$nextTick 里跑 toggleAllSelection 试一下

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/531353

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX