Vue3+element-plus:table表格设置反选,this.$refs.XXX.toggleRowSelection失效,

- 实现效果:

表格选择状态回显

反选失败原因及修正:

1、tab页循环,打印this.$refs可以看出是个数组,所以要加上对应的索引

2、this.$nextTick 是在下次 DOM 更新循环结束之后执行延迟回调,在修改数据之后使用 $nextTick,则可以在回调中获取更新后的 DOM。(注意this指向)

        <el-tabs tab-position="left" v-model="activeName" class="demo-tabs" @tab-change="handleNodeClick">
          <el-tab-pane 
          v-for="item in setTree"
          :key="item.sttp"
          :label="item.label"
          :name="item.sttp"
          >
          <div class="table jobdialog">
          <!-- 表格 -->
          <div style="margin-right:20px;">
            <el-table :data="ModelTableData"
              ref="modelParamsRefs"
              height='450px' style="width: 100%; font-size: 16px; border: 1px solid #e2e0e0;"
              @selection-change="handleSelectionChange">
                            <template v-slot:empty>
                              <img alt="" src="../../../public/common/nothingMild.png">
                              <p style="color: #969799;">暂无数据</p>
                            </template>
                            <el-table-column type="selection" width="55" />
                            <el-table-column :show-overflow-tooltip="true" align="center" label="参数名称" prop="name"
                                             width="auto">
                            </el-table-column>
                            <el-table-column :show-overflow-tooltip="true" align="center" label="参数范围"
                                             width="150">
                              <template #default="scope">
                                <span>{{scope.row.min }}- {{scope.row.max}}</span>
                                <!-- <span v-if="scope.row.fw=='-99999~-99999'">--</span>
                                <span v-else>{{ scope.row.fw }}</span> -->
                              </template>
                            </el-table-column>
                            <el-table-column :show-overflow-tooltip="true" align="center" label="参数类型" prop="datatype"
                                             width="100">
                          </el-table-column>
                          <el-table-column :show-overflow-tooltip="true" align="center" label="参数默认值" prop="defaultval"
                                             width="150">
                          </el-table-column>
                            <el-table-column align="center" label="参数值" width="120" prop="val">
                              <template #default="scope">
                                <!-- <el-input v-model="scope.row.paradefault"/> -->
                                <p>
                                  <el-input
                                      v-model="scope.row.val" @change="changeVal(scope.$index,scope.row)"/>
                                </p>
                              </template>
                            </el-table-column>
                            <el-table-column :show-overflow-tooltip="true" align="center" label="参数说明" prop="desc"
                                             width="200">
                            </el-table-column>
            </el-table>
          </div>
        </el-tab-pane>
      </el-tabs>

解决之后的代码

_this.$nextTick(()=>{
  flowparaarr.mskIndex.forEach((ele,index)=>{
  _this.$refs.modelParamsRefs[this.sttp-1].toggleRowSelection(this.ModelTableData[ele],true)
   })
})

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值