vue中使用element-ui實現分頁


請求數據加載之后進行分頁

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>

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM