溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

vue?elementui表格如何獲取某行數(shù)據(jù)

發(fā)布時間:2023-01-17 09:13:08 來源:億速云 閱讀:264 作者:iii 欄目:開發(fā)技術(shù)

這篇文章主要講解了“vue elementui表格如何獲取某行數(shù)據(jù)”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“vue elementui表格如何獲取某行數(shù)據(jù)”吧!

效果圖:

vue?elementui表格如何獲取某行數(shù)據(jù)

1.當(dāng)寫后臺管理頁面時,使用element ui里的table表格時,表格中有操作按鈕,獲取當(dāng)前行的數(shù)據(jù)時,我們可以使用 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)
    },

打印可得當(dāng)前行數(shù)據(jù),你就可以處理這些數(shù)據(jù)了

vue?elementui表格如何獲取某行數(shù)據(jù)

 2.但如果要實現(xiàn)的功能是在表頭上了,例如圖里的批量審核,那要怎么獲取當(dāng)前前勾選的這一行的數(shù)據(jù)呢?這時我們可以用表格中提供的@selection-change="handleSelectionChange" 的multipleSelection來實現(xiàn)。

<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="作品數(shù)量" 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;
    },

打印可得當(dāng)前行數(shù)據(jù),你就可以處理這些數(shù)據(jù)了

vue?elementui表格如何獲取某行數(shù)據(jù)

例如: 

<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 = [];
    //遍歷數(shù)據(jù)
        for (let item of this.multipleSelection) {
          planIdList.push(item.id);
        }
        this.propData.id = planIdList;
      }
    },

注意:this.multipleSelection.length 為選擇了多少項。

拿當(dāng)前選中的行的數(shù)據(jù),進行傳值,實現(xiàn)批量審核功能。

ps:Vue element怎么獲取table表格當(dāng)前行數(shù)據(jù)和索引值

怎么拿表格當(dāng)前行數(shù)據(jù)平時我們在使用表格時通過template的slot-scope="scope",使用scope.row拿到當(dāng)前行的數(shù)據(jù)

<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>

怎么拿表格當(dāng)前行索引值

<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表格如何獲取某行數(shù)據(jù)”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對vue elementui表格如何獲取某行數(shù)據(jù)這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關(guān)知識點的文章,歡迎關(guān)注!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI