温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

vue elementui表格如何获取某行数据

发布时间:2023-01-17 09:13:08 来源:亿速云 阅读:193 作者:iii 栏目:开发技术

这篇文章主要讲解了“vue elementui表格如何获取某行数据”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“vue elementui表格如何获取某行数据”吧!

效果图:

vue elementui表格如何获取某行数据

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)
    },

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

vue elementui表格如何获取某行数据

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

<template>
  <el-table
    ref="multipleTable"
    :data="tableData3"
    tooltip-effect="dark"
    
    @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;
    },

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

vue elementui表格如何获取某行数据

例如: 

<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 >
      <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 >
      <el-table-column label="序号">
            <template slot-scope="scope">
                  {{scope.$index+1}} 
            </template>
      </el-table-column>
</el-table>

感谢各位的阅读,以上就是“vue elementui表格如何获取某行数据”的内容了,经过本文的学习后,相信大家对vue elementui表格如何获取某行数据这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI