vue+iview分頁(yè)組件的封裝
vue+iview的分頁(yè)組件封裝
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> <!-- 分頁(yè)組件 --> <Page 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)前分頁(yè) type: [String, Number], default: 1 }, rows: { // 每頁(yè)顯示多少條 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: { // 分頁(yè)改變 currentChange (current) { this.params.page = current; this.onChange(); }, // 每頁(yè)顯示條數(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)前頁(yè)碼還原 // 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: { // 分頁(yè)切換 pageChange (params) { this.queryForm.page = params.page this.queryForm.rows = params.rows //查詢數(shù)據(jù)的方法 this.search(this.queryForm) }, }}</script>
關(guān)于vue.js組件的教程,請(qǐng)大家點(diǎn)擊專題vue.js組件學(xué)習(xí)教程進(jìn)行學(xué)習(xí)。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. ASP新手必備的基礎(chǔ)知識(shí)2. PHP基礎(chǔ)之生成器4——比較生成器和迭代器對(duì)象3. CentOS郵箱服務(wù)器搭建系列——SMTP服務(wù)器的構(gòu)建( Postfix )4. asp文件用什么軟件編輯5. Vue axios獲取token臨時(shí)令牌封裝案例6. js實(shí)現(xiàn)計(jì)算器功能7. JS中6個(gè)對(duì)象數(shù)組去重的方法8. 利用CSS制作3D動(dòng)畫9. JAVA 實(shí)現(xiàn)延遲隊(duì)列的方法10. 通過(guò)IEAD+Maven快速搭建SSM項(xiàng)目的過(guò)程(Spring + Spring MVC + Mybatis)

網(wǎng)公網(wǎng)安備