請求數據加載之后進行分頁
1.使用npm安裝
npm install element-ui -S
2.在main.js中引用
import ElementUI from 'element-ui'; import 'element-ui/lib/theme-chalk/index.css'; Vue.use(ElementUI);
3.在組件中的使用
<template> <div class="all"> <ul> <li class="single-box" v-for="(goods, index) in goodsData.slice((currentPage- 1)*pagesize,currentPage*pagesize)" :key="index" > </li> </ul> <div class="fenye"> <el-pagination background layout="prev, pager, next" :page-size="pagesize" @current-change="current_change" :current-page.sync="currentPage" :pager-count="5" :total="goodsData.length" > </el-pagination> </div> </div> </template> <script> import axios from "axios"; export default { name:'ListShow', data(){ return{ goodsData:[], pagesize:10,//每頁多少數據 currentPage:1 //默認當前頁為第一頁 } }, methods:{ current_change(currentPage){ //改變當前頁 this.currentPage = currentPage } }, mounted(){ axios .get("../../../data/data.json") .then((res) => { this.goodsData = res.data; console.log(res.data); }) .catch((err) => { console.error(err); }); } } </script>