elementPlus 分頁實現首頁,尾頁的功能

跪求出一個這個方法吧,自己寫真麻煩,但是也是閒着沒事,寫一個吧

 

                <div class="pagefun">
            <!--首頁按鈕 disabled是鼠標禁止狀態 pagenotallowd 鼠標禁用 一個紅色的圈加一個斜槓 -->
                    <button
                        :class="['firstpage',firstPageDisabled ? 'pagenotallowd' :'' ]"
                        :disabled="firstPageDisabled"
                        @click="gofirst"
                    > 
                       <DArrowLeft /> 
                    </button>  
                    <el-pagination
                        v-model:current-page="currentPage"
                        v-model:page-size="pageSize"
                        :page-sizes="[10, 20, 50, 100]"
                        :background="true"
                        layout="prev, pager, next, sizes,->,jumper"
                        :total="total"
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                    
                    /> 
                    <button
                        :class="['lastpage',lastPageDisabled ? 'pagenotallowd' :'' ]"
                        :disabled="lastPageDisabled"
                        @click="golast" 
                    >
                     <DArrowRight />
                    </button> 
                </div>
                
            </div>

  

 

 

引入icon文件:

import { DArrowRight, DArrowLeft } from '@element-plus/icons-vue';
const data = reactive({
    tableData:[],
    pageSize:10,
    total:0,
    pages:1,
    isdownload:false,
    firstPageDisabled:false,
    lastPageDisabled:false,
})
const currentPage = ref(1);
const handleSizeChange = (val: number) => {
  console.log(`${val} items per page`);
  data.pageSize = val; 
  getData();
}
const handleCurrentChange = (val: number) => {
  console.log(`current page: ${val}`);
  currentPage.value = val; 
  getData();
}
//去首頁
const gofirst = ()=>{
    handleCurrentChange(1);
}
//去尾頁
const golast = ()=>{
    handleCurrentChange(data.pages);
}

const getData = ()=>{
    let params = {
        pageNo:currentPage.value,
        pageSize:data.pageSize,
    }
    axios.getList(params).then((res: any) => {
        
        if (res.code == 200) {
            data.tableData = res.data.list;
            data.total = res.data.total; //總條數
            data.pages = res.data.totalNum; //總頁數
            if(data.pages  > 0 ){
                data.firstPageDisabled = currentPage.value === 1;
                data.lastPageDisabled = currentPage.value === data.pages ;
            }
        }
    });
}

const {
    tableData,
    pageSize,
    total,
    pages,
    isdownload,
    firstPageDisabled,
    lastPageDisabled,
} = toRefs(data);

 

 

 

 

css,我是把哪個箭頭定位過去的,因爲右側是固定寬度的,所以可以用定位實現

.pagefun{
                display: flex;
                align-items: center;
                .firstpage ,.lastpage{ 
                    width: 24px;
                    background: #fff;
                    margin-top: 2px; 
                }
                // 鼠標經過樣式
                .firstpage:hover ,.lastpage:hover{
                    color: #1682FF;
                }
                .lastpage{ 
                    position: absolute;
                    right: 350px;
                }
                // 鼠標禁止狀態
                .pagenotallowd{
                    cursor: no-drop;
                    cursor: not-allowed;
                }
            }
            :deep .el-pagination__sizes{
                margin-left: 70px;
            }
            :deep .el-pager li{ 
                border: 1px solid #DCDCDC;
            }
            :deep .el-pagination.is-background .el-pager li:not(.is-disabled).is-active{
                background-color: #1890FF!important;
                color: #FFFFFF;
                font-weight: 700;
            }
            :deep .el-pagination.is-background .btn-next, :deep .el-pagination.is-background .btn-prev, :deep .el-pager li{
                background: #fff;
            }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章