Element ui table(表格)和pagination(分页)

卞轶
2023-12-01
<template>
  <div>
    <el-table
      :data="tableData"
      style="width: 100%; 
border: 1px solid #D2E2FF;"
    >
      <el-table-column prop="createTime" label="充值时间" width="180">
      </el-table-column>
      <el-table-column prop="userName" label="操作人" width="180">
      </el-table-column>
      <el-table-column prop="rechargeDuration" label="充值时长">
      </el-table-column>
      <el-table-column prop="setMeal" label="充值套餐">
              <!-- 字符串变成对象 -->
        <template slot-scope="scope">
          {{ JSON.parse(scope.row.setMeal)[0].name }}
        </template>
      </el-table-column>
      <el-table-column prop="id" label="生效账号"> </el-table-column>
    </el-table>
    <el-pagination
      class="page_bottom"
      @current-change="currentChangeHandle"
      :current-page="page"
      :page-size="limit"
      :page-count="totalPage"
      layout="prev, pager, next, jumper"
      :hide-on-single-page="true"
    ></el-pagination>
  </div>
</template>

<script>
import _axios from "config/axios";
export default {
  data() {
    return {
      limit: 10, //最大页数
      page: 1, //当前页码
      totalPage: 1, //总页数
      tableData: [], //数据存放的数组
    };
  },
  created() {
    this.getData();
  },
  methods: {
    getData() {
      //请求封装成函数
      let params = {
        limit: this.limit,
        page: this.page,
      };
      _axios(
        `/qualityControl/sysdeptqualitybalancerecharge/list`,
        "POST",
        params
      ).then((res) => {
        console.log(res);
        if (res.data.code == 0) {
          //code等于0时可以正常访问
          this.tableData = res.data.page.list;
          this.totalPage = res.data.page.totalPage;
        } else {
          this.$alert(res.data.msg, "提示", {
            //报错提示
            confirmButtonText: "确定",
          });
        }
      });
    },
    // 当前页
    currentChangeHandle(val) {
      this.page = val; //改变当前页码
      this.getData();
    },
  },
};
</script>

<style lang="scss" scoped>
</style>

 类似资料: