传统分页和Element UI分页

以VUE文件为例

1、传统分页

<template>
  <div>
    <div class="header">
      <ul>
        <li v-for="(item,index) of newData" :key="index">{{item.jylx}}</li>
      </ul>
      <ul>
        <li v-if="currentPage === 1" class="disabled">上一页</li>
        <li v-else @click="LoadData(currentPage-1)">上一页</li>
        <li v-for="(item,index) of totalPages" :key="index" @click="LoadData(item)">{{item}}</li>
        <li v-if=" currentPage == totalPages ||  totalPages == 0" class="disabled">下一页</li>
        <li v-else @click="LoadData(currentPage+1)">下一页</li>
      </ul>
    </div>
  </div>
</template>

<script>
import axios from 'axios'
export default {
  name: "Library",
  data () {
    return {
      currentPage: 1,
      data: [],
      newData: [],
      pageSize:10,
      total: Number
    }
  },
  methods: {
    LoadData(value) {  //设置每一页显示10条数据
      this.currentPage = value
      this.newData = this.data.slice((value-1) * this.pageSize, value *this.pageSize)
    }
  },
  computed: {
    totalPages () {
      return Math.ceil(this.total *1 / this.pageSize )
    }
  },
  beforeCreate () {
    axios.get('/static/mock/card/card.json').then( (res) =>{
      if (res) {
        res = res.data
        this.data = res.data[0]
        this.total = res.data[0].length
        this.LoadData(1)  //默认加载第一页
      }
    })
  }
}
</script>

2、ElementUI

(1)先npm install Element-ui

(2)在man.js之中引入

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
Vue.use(ElementUI)

以vue文件为例

<template>
  <div>
    <div class="header">
      <el-table :data="data.slice((currentPage-1)*pageSize, currentPage*pageSize)">
        <el-table-column label="消费类型" prop="jylx"></el-table-column>
      </el-table>
      <el-pagination
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :total="total"
        layout="total, prev,pager, next,jumper"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import axios from 'axios'
export default {
  name: "Library",
  data () {
    return {
      currentPage: 1,
      data: [],
      pageSize:10,
      total: Number
    }
  },
  methods: {
    handleCurrentChange (currentPage) {
      this.currentPage = currentPage
    }
  },
  beforeCreate () {
    axios.get('/static/mock/card/card.json').then( (res) =>{
      if (res) {
        res = res.data
        this.data = res.data[0]
        this.total = res.data[0].length
      }
    })
  }
}
</script>

<style scoped>
</style>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值