vue el-tabs动态生成 每一个tab包含分别的分页 分页展示互不影响

最近有这样一个需求,一个弹框中有一个tabs切换且tab标签是动态的,每个tab中有一个表格和一个分页。那我们需要怎么做表格内容和分页互不影响呢?(效果如下)
在这里插入图片描述
在这里插入图片描述
接下来就讲讲具体的实现:
思路:
1. 获取到tabs标签列表 例如:parkingList
2. 在parkingList中添加page(分页)、allList(表格内容) parkingList:[ {page:{},allLiist:[]} ]
3. 用一个currentPark装当前选中的tab

 <el-tabs v-model="activeName" @tab-click="handClick">
        <el-tab-pane
          :label="ele.text"
          :name="String(ele.value)"
          v-for="ele in parkingList"
          :key="ele.value"
        >
          <el-table
            :data="ele.allList"
            style="width: 100%;height:7.375rem;overflow: auto;"
            :header-cell-style="{
              background: '#FAFAFA',
              color: '#000000',
              borderRight: '1px solid #fff'
            }"
          >
            <el-table-column label="#" min-width="20" type="index">
              <template slot-scope="scope">
                <span v-text="getIndex(scope.$index)"></span>
              </template>
            </el-table-column>
            <el-table-column label="号码" prop="plate_no">
            </el-table-column>
            <el-table-column label="小图">
              <template slot-scope="scope">
                <img
                  v-if="scope.row.plate_no_img"
                  :src="'data:image/jpeg;base64,' + scope.row.plate_no_img"
                  style="width: 127px;height: 35px;"
                />
                <span v-else>-</span>
              </template>
            </el-table-column>
            <el-table-column label="时间" prop="created_time">
              <template slot-scope="scope">
                {{ scope.row.catch_date | dataSecFormat }}
              </template>
            </el-table-column>
            <el-table-column label="所属人">
              <template slot-scope="scope">
                <span v-if="scope.row.own_name">{{ scope.row.own_name }}</span>
                <span v-else>-</span>
              </template>
            </el-table-column>
            <el-table-column label="名字">
              <template slot-scope="scope">
                <span v-if="scope.row.entrance_name">{{
                  scope.row.entrance_name
                }}</span>
                <span v-else>-</span>
              </template>
            </el-table-column>
            <el-table-column label="信息">
              <template slot-scope="scope">
                <span v-if="scope.row.parking_lot">{{
                  scope.row.parking_lot
                }}</span>
                <span v-else>-</span>
              </template></el-table-column
            >
          </el-table>
          <MyPagination
            @handleSizeChange="handleSizeChange"
            @handleCurrentChange="handleCurrentChange"
            :query="ele.page"
          />
        </el-tab-pane>
      </el-tabs>


	data() {
    return {
      activeName: '',// 当前选中的tab
      parkingList: [],
      currentPark: []
    }
  },
  methods:{
  	//tab切换事件
  	 handClick(val) {
      this.currentPark = this.parkingList.filter(
        item => item.value == this.activeName
      )
      if (this.currentPark[0].allList.length === 0) {
        this.getList()
      }
    },
    
    async getList(val) {
      this.currentPark[0].allList = []
      const {
        data: { content, totalElements }
      } = await this.$myRequest(this.$api.getCarRecordList, {
        center_id: Number(this.activeName),
        pageIndex: this.currentPark[0].page.pageIndex - 1,
        pageSize: this.currentPark[0].page.pageSize
      })
      this.currentPark[0].allList = content
      this.currentPark[0].page.total = totalElements
    },
    
    //每页多少条发生改变
    handleSizeChange(pageSize) {
      this.currentPark[0].page.pageSize = pageSize
      this.currentPark[0].page.pageIndex = 1
      this.getList()
    },
    
	//页码发生改变
    handleCurrentChange(pageIndex) {
      this.currentPark[0].page.pageIndex = pageIndex
      this.getList()
    }
  },
  watch: {
    visible: function(val) {
      if (!val) return
      if (this.parkingNameList.length != 0) {
        this.$nextTick(() => {
          this.activeName = String(this.parkingNameList[0].value)
          this.parkingList = []
          let temp = JSON.parse(JSON.stringify(this.parkingNameList))
          temp.forEach(item => {
            item = {
              ...item,
              page: { pageIndex: 1, pageSize: 10, total: 0 },
              allList: []
            }
            this.parkingList.push(item)
          })
          this.currentPark = this.parkingList.filter(
            item => item.value == this.activeName
          )
          this.getList()
        })
      }
    }
  }

提示:我这个办法并不是最优的,如你有更优的解决办法可以给我讲讲哟~

  • 3
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值