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

設計要的效果圖

上代碼
這里用到了自定義指令,如果大家用不到可以安自己的實際效果開發(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: 用于自動注冊全局自定義指令
* 使用規(guī)則:
* 根據(jù)導出的name在頁面使用如directives對象中的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
// 獲取最后一個/的索引
const index = start.lastIndexOf('/')
// 獲取最后一個/后面的值
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)建兩個文件index.css,index.js
index.js寫業(yè)務邏輯
/*
* @Author: 周云芳
* @Date: 2022-07-19 09:12:39
* @LastEditors: 周云芳 164591357@qq.com
* @LastEditTime: 2022-10-21 15:05:49
* @Description:設置分頁為左右布局 指令使用 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)建兩個左右div
const liDom = document.createElement('li')
liDom.className = 'size-change-li'
// RDiv.className = 'right-div'
liDom.appendChild(sizeChange)
el.insertBefore(liDom, prev) // 在上一頁前插入節(jié)點
}, 100)
}
}效果:

index.css 進行樣式調(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)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
echarts堆疊柱狀圖柱子之間間隔開具體實現(xiàn)代碼
ECharts是一個強大的數(shù)據(jù)可視化庫,它的堆疊柱狀圖通常用于比較各個分類的數(shù)據(jù)總量,這篇文章主要給大家介紹了echarts堆疊柱狀圖柱子之間間隔開具體實現(xiàn)的相關(guān)資料,需要的朋友可以參考下2024-11-11
js接收并轉(zhuǎn)化Java中的數(shù)組對象的方法
下面小編就為大家?guī)硪黄猨s接收并轉(zhuǎn)化Java中的數(shù)組對象的方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-08-08
使用JavaScript下載圖片并保存到本地的詳細解釋和代碼示例
在前端開發(fā)中經(jīng)常會遇到需要將圖片從網(wǎng)絡上下載并保存到本地的需求,這篇文章主要給大家介紹了關(guān)于使用JavaScript下載圖片并保存到本地的詳細解釋和代碼示例,文中通過代碼介紹的非常詳細,需要的朋友可以參考下2024-07-07
js 獲取網(wǎng)絡圖片的高度和寬度的實現(xiàn)方法(變通了下)
簡單地說就是把圖片放入一個自動伸縮的DIV中,然后獲取DIV的寬和高!這個不錯的變通,大家可以參考下。2009-10-10

