默认勾选一行 form -item

在Vue.js应用中遇到默认勾选FormItem时可能会遇到失效问题。为确保数据加载完成后才执行勾选操作,可以使用`this.$nextTick`确保DOM更新后再进行设置,默认选一行或全选。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

默认勾选失效问题
注意要当数据都加载完的时候 再去 勾选 使用this.$nextTick即可

 <el-table ref="multipleTable" :data="tableData" style="width: 100%" selection-change="tableSelectChange">
        <el-table-column
            type="selection"
            width="55">
        </el-table-column>
        <el-table-column
            label="名称"
            width="120">
            <template slot-scope="scope">{{ scope.row.detailName }}</template>
        </el-table-column>
        <el-table-column
            label="单价(元)"
            width="120">
            <template slot-scope="scope">{{ scope.row.money }}</template>
        </el-table-column>
    </el-table>

默认选一行

this.$nextTick(function () {
  this.$refs.multipleTable.toggleRowSelection(this.tableData[this.tableData.length-1],true);
   });
});

默认全选

 this.$nextTick(function () {
      this.tableData.forEach(row => {
          this.$refs.multipleTable.toggleRowSelection(row,true);
      });
  });
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值