antDesign 自定義分頁樣式的實(shí)現(xiàn)代碼
原圖

設(shè)計(jì)要的效果圖

上代碼
這里用到了自定義指令,如果大家用不到可以安自己的實(shí)際效果開發(fā)
創(chuàng)建directive/index.js頁面用于把所有自定義指令可以一次引入
/*
* @Author: 周云芳
* @Date: 2022-06-28 15:21:41
* @LastEditors: 周云芳 164591357@qq.com
* @LastEditTime: 2022-10-21 14:26:58
* @Description: 用于自動(dòng)注冊(cè)全局自定義指令
* 使用規(guī)則:
* 根據(jù)導(dǎo)出的name在頁面使用如directives對(duì)象中的name為a-pagination,頁面使用:v-a-pagination
*/
const requireDirective = require.context('./', true, /\.js$/)
// 自定義指令
let directives = {}
requireDirective.keys().map(file => {
// console.log('file', file)
const name = removerLastIndex(file)
console.log('name', name)
if (name) {
directives = {
...directives,
[name]: requireDirective(file).default
}
}
return false
})
function removerLastIndex(str) {
const start = str.substring(2, str.length) // 去除路徑中的./ start=el-drag-dialog/index.js
// str = login/index
// 獲取最后一個(gè)/的索引
const index = start.lastIndexOf('/')
// 獲取最后一個(gè)/后面的值
const val = start.substring(index + 1, start.length)
// 判斷是不是index結(jié)尾
if (val === 'index.js') {
return start.substring(index, -1)
}
return str
}
export default {
install(Vue) {
Object.keys(directives).forEach(key => {
Vue.directive(key, directives[key])
})
}
}創(chuàng)建分頁指令頁面在directive文件夾下建a-pagination這文件夾下創(chuàng)建兩個(gè)文件index.css,index.js
index.js寫業(yè)務(wù)邏輯
/*
* @Author: 周云芳
* @Date: 2022-07-19 09:12:39
* @LastEditors: 周云芳 164591357@qq.com
* @LastEditTime: 2022-10-21 15:05:49
* @Description:設(shè)置分頁為左右布局 指令使用 v-el-pagination
*/
import './index.css'
export default {
inserted: (el, binding) => {
setTimeout(() => {
// 把分頁條數(shù)放入總條數(shù)后
const options = el.getElementsByClassName('ant-pagination-options')[0]
const sizeChange = options.getElementsByClassName(
'ant-pagination-options-size-changer'
)[0] // 分頁數(shù)
const prev = el.getElementsByClassName('ant-pagination-prev')[0]
// // 創(chuàng)建兩個(gè)左右div
const liDom = document.createElement('li')
liDom.className = 'size-change-li'
// RDiv.className = 'right-div'
liDom.appendChild(sizeChange)
el.insertBefore(liDom, prev) // 在上一頁前插入節(jié)點(diǎn)
}, 100)
}
}效果:

index.css 進(jìn)行樣式調(diào)整
.size-change-li {
display: inline-block;
}
.ant-pagination-prev .ant-pagination-item-link,
.ant-pagination-next .ant-pagination-item-link,
.ant-pagination-item {
border: none;
}
.ant-pagination-item {
font-family: 'PingFang SC';
font-style: normal;
font-weight: 400;
font-size: 14px;
}
.ant-pagination-item-active {
background: #3296FA;
border-radius: 4px;
}
.ant-pagination-item-active a,.ant-pagination-item-active:focus a, .ant-pagination-item-active:hover a{
color: #FFFFFF;
}最后效果

最后記得全局自定義指令要在main.js引入
import Directive from '@/directive' Vue.use(Directive)
頁面使用指令 v-a-pagination
<a-pagination v-a-pagination show-quick-jumper show-size-changer :total="total" :show-total="total => `總共 ${total} 條`" @change="onChange" />到此這篇關(guān)于antDesign 自定義分頁樣式的文章就介紹到這了,更多相關(guān)antDesign 自定義分頁內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
web頁面和微信小程序頁面實(shí)現(xiàn)瀑布流效果
這篇文章主要介紹了web頁面和微信小程序頁面實(shí)現(xiàn)瀑布流效果,本文通過實(shí)例代碼圖文介紹,給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值 ,需要的朋友可以參考下2018-09-09
通過JAVAScript實(shí)現(xiàn)頁面自適應(yīng)
通過JAVAScript實(shí)現(xiàn)頁面自適應(yīng)...2007-01-01
echarts堆疊柱狀圖柱子之間間隔開具體實(shí)現(xiàn)代碼
ECharts是一個(gè)強(qiáng)大的數(shù)據(jù)可視化庫,它的堆疊柱狀圖通常用于比較各個(gè)分類的數(shù)據(jù)總量,這篇文章主要給大家介紹了echarts堆疊柱狀圖柱子之間間隔開具體實(shí)現(xiàn)的相關(guān)資料,需要的朋友可以參考下2024-11-11
js接收并轉(zhuǎn)化Java中的數(shù)組對(duì)象的方法
下面小編就為大家?guī)硪黄猨s接收并轉(zhuǎn)化Java中的數(shù)組對(duì)象的方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-08-08
使用JavaScript下載圖片并保存到本地的詳細(xì)解釋和代碼示例
在前端開發(fā)中經(jīng)常會(huì)遇到需要將圖片從網(wǎng)絡(luò)上下載并保存到本地的需求,這篇文章主要給大家介紹了關(guān)于使用JavaScript下載圖片并保存到本地的詳細(xì)解釋和代碼示例,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下2024-07-07
js 獲取網(wǎng)絡(luò)圖片的高度和寬度的實(shí)現(xiàn)方法(變通了下)
簡單地說就是把圖片放入一個(gè)自動(dòng)伸縮的DIV中,然后獲取DIV的寬和高!這個(gè)不錯(cuò)的變通,大家可以參考下。2009-10-10
JavaScript獲取服務(wù)器端時(shí)間的方法
這篇文章主要介紹了JavaScript獲取服務(wù)器端時(shí)間的方法,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-11-11

