国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

elementui實(shí)現(xiàn)當(dāng)前頁(yè)全選+所有全選+翻頁(yè)保持選中狀

這篇具有很好參考價(jià)值的文章主要介紹了elementui實(shí)現(xiàn)當(dāng)前頁(yè)全選+所有全選+翻頁(yè)保持選中狀。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

elementui實(shí)現(xiàn)當(dāng)前頁(yè)全選+所有全選+翻頁(yè)保持選中狀,javascript,開(kāi)發(fā)語(yǔ)言,ecmascript文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-634245.html

//代碼可直接復(fù)制看效果,
<template>
  <div>
    <el-button @click="submitData()">提交列表選中數(shù)據(jù)</el-button>
    <!--列表-->
    <el-table
      ref="table"
      v-loading="listLoading"
      :data="lists"
      highlight-current-row
      style="width: 100%"
      :row-key="
        (row) => {
          return row.id;
        }
      "
      @select="handleSelectRow"
      @select-all="handleSelectAll"
    >
      <el-table-column type="selection" :reserve-selection="true" />
      <el-table-column prop="id" label="id" />
      <el-table-column prop="time" label="time" />
    </el-table>
    <!--工具條-->
    <el-col :span="24" class="toolbar">
      <el-pagination
        :current-page="this.page"
        layout="total , prev, pager, next"
        :page-size="10"
        :total="total"
        style="float: right"
        @current-change="handleCurrentChange"
      />
    </el-col>
    <div class="clearfix" />
  </div>
</template>
<script>
export default {
  data() {
    return {
      lists: [
        { id: "1", time: "2019-09-09 12:12:12" },
        { id: "2", time: "2019-09-09 12:12:12" },
        { id: "3", time: "2019-09-09 12:12:12" },
        { id: "4", time: "2019-09-09 12:12:12" },
        { id: "5", time: "2019-09-09 12:12:12" },
        { id: "6", time: "2019-09-09 12:12:12" },
        { id: "7", time: "2019-09-09 12:12:12" },
        { id: "8", time: "2019-09-09 12:12:12" },
        { id: "9", time: "2019-09-09 12:12:12" },
        { id: "10", time: "2019-09-09 12:12:12" },
      ],

      total: 13, // 得到的列表總數(shù)
      page: 1,
      listLoading: false,
      checkList: [],
      checkIds: [],
    };
  },
  mounted() {
    this.getData(this.lists); // 模擬接口查詢列表數(shù)據(jù)
  },
  methods: {
    // 分頁(yè)
    handleCurrentChange(val) {
      this.page = val;
      if (val === 1) {
        this.lists = [
          { id: "1", time: "2019-09-09 12:12:12" },
          { id: "2", time: "2019-09-09 12:12:12" },
          { id: "3", time: "2019-09-09 12:12:12" },
          { id: "4", time: "2019-09-09 12:12:12" },
          { id: "5", time: "2019-09-09 12:12:12" },
          { id: "6", time: "2019-09-09 12:12:12" },
          { id: "7", time: "2019-09-09 12:12:12" },
          { id: "8", time: "2019-09-09 12:12:12" },
          { id: "9", time: "2019-09-09 12:12:12" },
          { id: "10", time: "2019-09-09 12:12:12" },
        ];
      } else {
        this.lists = [
          { id: "11", time: "2019-09-09 12:12:12" },
          { id: "12", time: "2019-09-09 12:12:12" },
          { id: "13", time: "2019-09-09 12:12:12" },
        ];
      }
    },

    // 模擬接口返回的展示列表數(shù)據(jù)
    getData(lists) {
      console.log(lists);
      // 每一次執(zhí)行數(shù)據(jù)請(qǐng)求的方法時(shí),在請(qǐng)求成功的方法里執(zhí)行回顯
      if (this.checkList !== undefined) {
        this.checkList.forEach((key) => {
          this.lists.forEach((row) => {
            if (row.id === key.id) {
              // 新增的時(shí)候
              this.$refs.table.toggleRowSelection(row, true);
            }
          });
        });
      }
    },
    // 獲取取消勾選的其余已勾選數(shù)據(jù)
    handleSelectRow(selecteds, rows) {
      this.checkList = selecteds;
    },

    // 獲取單頁(yè)全選的數(shù)據(jù)
    handleSelectAll(rows) {
      this.checkList = rows;
    },

    // 單頁(yè)選中的數(shù)據(jù)的id數(shù)組提交時(shí)返回給后端保存
    submitData() {
      // 獲取所有選中的id的集合,用于提交時(shí)調(diào)用接口傳參數(shù)this.checkIds
      for (var i = 0; i < this.checkList.length; i++) {
        if (this.checkList[i] !== undefined && this.checkList.length > 0) {
          this.checkIds = this.checkList.map((item) => item.id);
        }
      }

      console.log(this.checkIds); // ['1', '2', '3', '4', '5', '6', '11', __ob__: Observer]
    },
  },
};
</script>
<style></style>


到了這里,關(guān)于elementui實(shí)現(xiàn)當(dāng)前頁(yè)全選+所有全選+翻頁(yè)保持選中狀的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包