vue elementui表格获取某行数据(slot-scope和selection-change方法使用)

效果图:

1.当写后台管理页面时,使用element ui里的table表格时,表格中有操作按钮,获取当前行的数据时,我们可以使用 slot-scope="scope"来获取。

 <el-table-column label="操作" align="center" prop="auditStatus" width="180" fixed="right">
      <template slot-scope="scope">
       <el-button type="text" size="large" @click="audit(scope.row)">审核</el-button>
       </template>
</el-table-column>
  audit(row){
     console.log(row)
    },

打印可得当前行数据,你就可以处理这些数据了

 2.但如果要实现的功能是在表头上了,例如图里的批量审核,那要怎么获取当前前勾选的这一行的数据呢?这时我们可以用表格中提供的@selection-change="handleSelectionChange" 的multipleSelection来实现。

<template>
  <el-table
    ref="multipleTable"
    :data="tableData3"
    tooltip-effect="dark"
    style="width: 100%"
    @selection-change="handleSelectionChange">
    <el-table-column
      type="selection"
      width="55">
    </el-table-column>
    <el-table-column prop="title" label="作品名称" align="center" width="160">
    </el-table-column>
    <el-table-column prop="count" label="作品数量" align="center" min-width="160">
    </el-table-column>
    <el-table-column prop="price" label="作品价格" align="center" min-width="160">
    </el-table-column>
  </el-table>
</template>
 data(){
  return {
    multipleSelection:[]
   }
} 
//获取所有选择的项
    handleSelectionChange(val) {
    console.log(val)
      this.multipleSelection = val;
    },

打印可得当前行数据,你就可以处理这些数据了

例如: 

<el-form-item>
        <el-button type="primary" @click="batchTransferTip()">批量审核</el-button>
</el-form-item>
    //批量审核
    batchTransferTip() {
      if (this.multipleSelection.length == 0) {
        this.common.messageTip("请选择要审核的作品", "error");
        return false;
      } else {
        this.editboxName = "verify";
        let planIdList = [];
    //遍历数据
        for (let item of this.multipleSelection) {
          planIdList.push(item.id);
        }
        this.propData.id = planIdList;
      }
    },

注意:this.multipleSelection.length 为选择了多少项。

拿当前选中的行的数据,进行传值,实现批量审核功能。

  • 17
    点赞
  • 52
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

阿wei程序媛

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值