当前位置: 代码网 > it编程>前端脚本>Vue.js > vue elementui表格获取某行数据(slot-scope和selection-change方法使用)

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

2024年06月01日 Vue.js 我要评论
效果图:1.当写后台管理页面时,使用element ui里的table表格时,表格中有操作按钮,获取当前行的数据时,我们可以使用 slot-scope="scope"来获取。 &l

效果图:

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 为选择了多少项。

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

ps:vue element怎么获取table表格当前行数据和索引值

怎么拿表格当前行数据平时我们在使用表格时通过template的slot-scope="scope",使用scope.row拿到当前行的数据

<el-table max-height="290" :data="usertabledata" border style="width: 100%">
      <el-table-column label="名字">
            <template slot-scope="scope">
              {{scope.row.name}}
            </template>
      </el-table-column>
       <el-table-column label="年龄">
            <template slot-scope="{row}">
              {{row.age}}
            </template>
      </el-table-column>
</el-table>

怎么拿表格当前行索引值

<el-table max-height="290" :data="usertabledata" border style="width: 100%">
      <el-table-column label="序号">
            <template slot-scope="scope">
                  {{scope.$index+1}} 
            </template>
      </el-table-column>
</el-table>

到此这篇关于vue elementui表格获取某行数据(slot-scope和selection-change方法使用)的文章就介绍到这了,更多相关vue elementui表格获取某行数据内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com