vue+iview分頁組件的封裝
vue+iview的分頁組件封裝
1.在components中創(chuàng)建pagination文件夾,接著創(chuàng)建src,index.js,index.less文件
2.index.less文件
//需要修改的樣式
.ivu-page-options {
margin-left: 10px;
.ivu-page-options-sizer {
margin-right: 0;
}
}
3.index.js文件
import "./index.less";
import component from "./src/main";
/* istanbul ignore next */
component.install = function (Vue) {
Vue.component(component.name, component);
};
export default component;
4.src文件夾中的main.vue
<template>
<!-- 分頁組件 -->
<Page
class="saas-pagination"
ref="page"
:loading="loading"
:disabled="disabled"
:total="total"
:show-sizer="sizer"
:show-elevator="elevator"
:current="params.page"
:page-size="params.rows"
:page-size-opts="sizeOpts"
@on-change="currentChange"
@on-page-size-change="pageChange"/>
</template>
<script>
export default {
props: {
loading: {
type: Boolean,
default: false
},
total: {
// 數(shù)據(jù)總數(shù)
type: [String, Number],
default: 0
},
page: {
// 當(dāng)前分頁
type: [String, Number],
default: 1
},
rows: {
// 每頁顯示多少條
type: [String, Number],
default: 10
},
disabled: {
type: Boolean,
default: false
},
sizer: {
// 是否顯示下拉組件
type: Boolean,
default: false
},
elevator: {
// 是否顯示跳轉(zhuǎn)輸入框
type: Boolean,
default: false
}
},
watch: {
page (to) {
this.params.page = to;
},
rows (to) {
this.params.rows = to;
}
},
data () {
return {
sizeOpts: [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],
params: {
page: 1,
rows: 10
}
}
},
methods: {
// 分頁改變
currentChange (current) {
this.params.page = current;
this.onChange();
},
// 每頁顯示條數(shù)改變
pageChange (rows) {
this.params.page = 1;
this.params.rows = rows;
this.onChange();
},
onChange () {
this.$emit("on-change", JSON.parse(JSON.stringify(this.params)));
},
reset () {
this.params = {
page: 1,
rows: 10
}
this.onChange();
// 當(dāng)前頁碼還原
// this.$refs.page.currentPage = 1;
}
}
}
</script>
5.在components中創(chuàng)建index.js,用于全局引入
import GlobalPage from "@/components/pagination/index.js";
export default (Vue) => {
Vue.component("GlobalPage ", GlobalPage );
}
6然后在全局的main.js引入,可全局使用
import components from "@/components/index.js"; Vue.use(components)
7.組件的使用
<template>
<div>
<global-page
ref="pagination"
:sizer="true"
:page="formData.page"
:rows="formData.rows"
:total="total"
@on-change="pageChange">
</global-page>
</div>
</template>
<script>
export default {
data(){
return {
total: 0, // 數(shù)據(jù)總數(shù)
queryForm:{},
formData: {
page: 1,
rows: 10,
}
}
},
methods: {
// 分頁切換
pageChange (params) {
this.queryForm.page = params.page
this.queryForm.rows = params.rows
//查詢數(shù)據(jù)的方法
this.search(this.queryForm)
},
}
}
</script>
關(guān)于vue.js組件的教程,請大家點(diǎn)擊專題vue.js組件學(xué)習(xí)教程進(jìn)行學(xué)習(xí)。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Vue + element實(shí)現(xiàn)動態(tài)顯示后臺數(shù)據(jù)到options的操作方法
最近遇到一個(gè)需求需要實(shí)現(xiàn)selector選擇器中選項(xiàng)值options 數(shù)據(jù)的動態(tài)顯示,而非寫死的數(shù)據(jù),本文通過實(shí)例代碼給大家分享實(shí)現(xiàn)方法,感興趣的朋友一起看看吧2021-07-07
Vue中textarea自適應(yīng)高度方案的實(shí)現(xiàn)
本文主要介紹了Vue中textarea自適應(yīng)高度方案的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-01-01
vue-router的鉤子函數(shù)用法實(shí)例分析
這篇文章主要介紹了vue-router的鉤子函數(shù)用法,結(jié)合實(shí)例形式分析了vue路由鉤子分類及vue-router鉤子函數(shù)相關(guān)使用技巧,需要的朋友可以參考下2019-10-10
Vue中.vue文件比main.js先執(zhí)行的問題及解決
這篇文章主要介紹了Vue中.vue文件比main.js先執(zhí)行的問題及解決方案,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-12-12
Vue 組件(component)教程之實(shí)現(xiàn)精美的日歷方法示例
組件是我們學(xué)習(xí)vue必須會的一部分,下面這篇文章主要給大家介紹了關(guān)于Vue 組件(component)教程之實(shí)現(xiàn)精美的日歷的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2018-01-01
Vue3封裝全局Dialog組件的實(shí)現(xiàn)方法
3封裝全局Dialog組件相信大家都不陌生,下面這篇文章主要給大家介紹了關(guān)于Vue3封裝全局Dialog組件的實(shí)現(xiàn)方法,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-06-06

