vue+element组件实现分页

1.页面代码

根据分页容量来限制每页条数:list.slice((currentPage - 1) * pageSize, currentPage * pageSize)"

获取分页中每条数据的序号(currentPage - 1) * pageSize+scope.$index + 1

    <el-table :data="list.slice((currentPage - 1) * pageSize, currentPage * pageSize)" border fit highlight-current-row>
      <el-table-column label="序号" width="70" align="center">
        <template slot-scope="scope">
          {{(currentPage - 1) * pageSize+scope.$index + 1 }}
          <!-- {{ (page - 1) * limit + scope.$index + 1 }} -->
        </template>
      </el-table-column>

      <el-table-column prop="articleTitle" label="文章标题" width="350" />

      <el-table-column label="头衔" width="80">
        <template slot-scope="scope">
          {{ scope.row.level === 1 ? "高级讲师" : "首席讲师" }}
        </template>
      </el-table-column>

      <el-table-column prop="intro" label="资历" />

      <el-table-column prop="gmtCreate" label="创建时间" width="160" />

      <el-table-column prop="sort" label="排序" width="60" />

      <el-table-column label="操作" width="200" align="center">
        <template slot-scope="scope">
          <router-link :to="'/teacher/edit/' + scope.row.id">
            <el-button type="primary" size="mini" icon="el-icon-edit"
              >修改</el-button
            >
          </router-link>
          <el-button
            type="danger"
            size="mini"
            icon="el-icon-delete"
            @click="removeDataById(scope.row.id)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

page-size:页面容量
total:总条数

    <el-pagination
      @current-change="change"
      background
      layout="total,prev, pager, next,jumper"
      :page-size="pageSize"
      :total="list.length"
    ></el-pagination>
<script>
export default {
  data() {
    return {
      pageSize: 8,
      total: 10,
      currentPage: 1,

      list: null,
    };
  },
  methods: {
    change(currentPage) {
      this.currentPage = currentPage;
    },

    // 
    getArticleList() {
      var _this = this;
      this.$axios
        .get("http://localhost:8088/articles/findAllArticles")
        .then(function (resp) {
        //将取得的数据赋值给list
          _this.list = resp.data.data.Articles;
        });
    },
  },
  created() {
    this.getArticleList();
  },
};
</script>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue Element UI提供了el-pagination组件实现表格数据的分页功能。以下是实现步骤: 1. 在Vue组件中引入el-pagination组件并定义分页属性 ``` <template> <div> <el-table :data="tableData" border> //表格内容 </el-table> <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="[10, 20, 30, 40]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total"> </el-pagination> </div> </template> <script> export default { data() { return { tableData: [], //表格数据 total: 0, //总记录数 pageSize: 10, //每页记录数 currentPage: 1 //当前页码 }; }, methods: { handleSizeChange(val) { this.pageSize = val; this.getData(); }, handleCurrentChange(val) { this.currentPage = val; this.getData(); }, getData() { //获取数据,并更新this.tableData和this.total } } }; </script> ``` 2. 在el-pagination组件中绑定事件和属性 - @size-change:当每页显示条数改变时触发的事件,调用handleSizeChange方法更新pageSize并重新获取数据。 - @current-change:当当前页码改变时触发的事件,调用handleCurrentChange方法更新currentPage并重新获取数据。 - :current-page:当前页码,绑定到currentPage属性。 - :page-sizes:每页显示条数数组,可以自定义,默认为[10, 20, 30, 40]。 - :page-size:每页显示条数,绑定到pageSize属性。 - layout:分页组件布局。其中total表示总记录数,sizes表示每页显示条数选择器,prev表示上一页按钮,pager表示页码按钮,next表示下一页按钮,jumper表示跳转输入框和确定按钮。 - :total:总记录数,绑定到total属性。 3. 在getData方法中获取数据并更新表格数据和总记录数 ``` getData() { //计算分页查询的参数 const start = (this.currentPage - 1) * this.pageSize; const limit = this.pageSize; //发起分页查询请求 axios.get('/api/data', { params: { start, limit } }).then(response => { this.tableData = response.data.rows; //更新表格数据 this.total = response.data.total; //更新总记录数 }); } ``` 以上就是使用Vue Element UI实现表格数据分页功能的步骤。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值