vue項目實現(xiàn)分頁效果
更新時間:2021年03月18日 14:55:16 作者:程序猿余某人
這篇文章主要為大家詳細介紹了vue項目實現(xiàn)分頁效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
vue項目中實現(xiàn)分頁效果,供大家參考,具體內(nèi)容如下
1.這里我們使用element-ui來實現(xiàn),先使用npm安裝
npm i element-ui -S
2.在main.js中全局引入
import ElementUI from "element-ui" import 'element-ui/lib/theme-chalk/index.css' Vue.use(ElementUI) //將element-ui掛在到全局
3.封裝組件
<template> <div class="block"> <el-pagination @current-change="handleCurrentChange" :current-page="currentPage" :page-size="6" layout="prev, pager, next, jumper" :total="total" :pager-count="5" > </el-pagination> </div> </template> <script> export default { props: ["num", "page"], //傳入的總條數(shù),和頁碼 data() { return {}; }, computed: { currentPage: function() { return this.page; }, total: function() { return this.num; } }, methods: { handleSizeChange(val) { this.$emit("size-change", val); }, handleCurrentChange(val) { this.$emit("current-change", val); } } }; </script> <style> .block { text-align: right; /* width: 100%; */ } </style>
4.引入組件并使用
<template> <div class="mobild"> <div> <ATablePaging :num="num" :page="page" @current-change="(val) => { page = val; list(); }" ></ATablePaging> </div> </div> </template> <script> import ATablePaging from "../paging"; //引入分頁組件 export default { data() { return { page:"", //當前頁碼 num: 1, //內(nèi)容總條數(shù) }; }, methods: { list() { //發(fā)送的http請求 //后端返回的總頁數(shù)等于num }, }, mounted() { this.news(); }, components: { ATablePaging } }; </script> <style scoped> </style>
關(guān)于vue.js的學(xué)習(xí)教程,請大家點擊專題vue.js組件學(xué)習(xí)教程、Vue.js前端組件學(xué)習(xí)教程進行學(xué)習(xí)。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Vue.js遞歸組件實現(xiàn)組織架構(gòu)樹和選人功能
這篇文章主要介紹了Vue.js遞歸組件實現(xiàn)組織架構(gòu)樹和選人功能,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-07-07Vue.js實現(xiàn)一個SPA登錄頁面的過程【推薦】
本篇文章主要介紹了Vue.js寫一個SPA登錄頁面過程的相關(guān)知識,具有很好的參考價值。下面跟著小編一起來看下吧2017-04-04