码迷,mamicode.com
首页 > 其他好文 > 详细

实现分页加载,加载更多(按钮类型),滚动加载的方式

时间:2020-10-21 21:27:16      阅读:29      评论:0      收藏:0      [点我收藏+]

标签:滚动   ini   javascrip   param   方式   com   current   ios   export   

基于vue语法

分页加载(vue+element -ui)

<template>
  <div>
    <el-pagination
      class="pagination"
      background
      layout="prev, pager, next"
      :pageSize="pageSize"
      :total="total"
      @current-change="handleChange"
    >
    </el-pagination>
  </div>
</template>
<script>
import { Pagination, Button } from "element-ui"; //局部引入分页组件
export default {
  name: "demo",
  components: {
    [Pagination.name]: Pagination,
  },
  data() {
    return {
      pageSize: 3,
      pageNum: 1,
      total: 0,
    };
  },
  mounted() {
    this.getOrderList();
  },
  methods: {
    getOrderList() {
      this.axios
        .get("/orders", {
          params: {
            pageSize: this.pageSize,
            pageNum: this.pageNum,
          },
        })
        .then((res) => {
          this.list = res.list;
          this.total = res.total;
          this.loading = false;
        })
        .catch(() => {
          this.loading = false;
        });
    },
    //分页器分页
    handleChange(pageNum) {
      this.pageNum = pageNum;
      this.getOrderList();
    },
  },
};
</script>

<style></style>

  

加载更多

  点击按钮加载更多,始终一屏显示,加载数据拼接在原数据后面!

<template>
  <div>
    <el-button type="primary" :loading="loading" @click="loadMore"
      >加载更多</el-button
    >
  </div>
</template>
<script>
import { Button } from "element-ui"; //局部引入分页组件
export default {
  name: "demo",
  components: {
    [Button.name]: Button,
  },
  data() {
    return {
      pageSize: 3,
      pageNum: 1,
    };
  },
  mounted() {
    this.getOrderList();
  },
  methods: {
    getOrderList() {
      this.axios
        .get("/orders", {
          params: {
            pageSize: this.pageSize,
            pageNum: this.pageNum,
          },
        })
        .then((res) => {
          this.list = this.list.concat(res.list);//拼接原数据
          this.total = res.total;
          this.loading = false;
        })
        .catch(() => {
          this.loading = false;
        });
    },
    loadMore() {
      this.getOrderList();
    },
  },
};
</script>
<style></style>

  

滚动加载数据

1.使用插件   vue-infinite-scroll

2.使用插件better-scroll

 

   可查看相关文档哈

实现分页加载,加载更多(按钮类型),滚动加载的方式

标签:滚动   ini   javascrip   param   方式   com   current   ios   export   

原文地址:https://www.cnblogs.com/hudunyu/p/13853692.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!