vue3+ts封裝彈窗及封裝分頁(yè)的示例代碼
定義defaultDialog .vue
<script lang="ts" setup>
import { ref,toRefs,onUpdated } from 'vue'
import { ElMessageBox } from 'element-plus'
const props =defineProps({//接收參數(shù),父組件傳的時(shí)候用:msg='123'的形式
msg:String,
show:{
type:Boolean,
default:false
},
title: {
type:String,
require: '',
default: '中型彈窗'
},
noFooter: {
type:Boolean,
require: false,
default: false
}
// "diaVisible", "title", "width", "noFooter","top"
})
const emit = defineEmits<{//定義組件含有的方法,父組件用@close='closefn()'的形式監(jiān)聽(tīng)
close: [] // 具名元組語(yǔ)法
cancel: []
save: []
}>()
const close = () => {//這里是觸發(fā)事件,觸發(fā)父組件監(jiān)聽(tīng)的方法
emit('close')
}
const save = () =>{
emit('save')
}
const cancel = (val:any) => {
emit('cancel')
}
const createForm1 = ref(null)
const createForm2 = ref(null)
onUpdated(()=>{
document.getElementById("div");
let height1 = createForm1.value
})
</script>
<template>
<div class="myDialog">
<el-dialog
width="104rem"
style="height: 67%;min-height: 620px;min-width: 900px;"
:title="props.title"
v-model="props.show"
v-dialogDrag
v-if="props.show"
:before-close="close"
>
<!-- 自定義插槽 noFooter為true的時(shí)候,不顯示footer的插槽-->
<slot name="dia_Content"></slot>
<div
class="dialog-footer"
v-if="noFooter ? false : true"
>
<el-button type="primary" size="large" @click="save" color="#4088FE"> 確 定 </el-button>
<div style="width: 4rem;"></div>
<el-button size="large" @click="cancel" color="rgba(132, 158, 199, 1)"> 取 消 </el-button>
</div>
</el-dialog>
</div>
</template>
<style lang="scss" scoped>
.el-form-item__content{
width: 100%;
}
:deep(.el-cascader.el-tooltip__trigger.el-tooltip__trigger){
width: 100% !important;
}
:deep(.el-input.el-input--prefix.el-input--suffix.el-date-editor.el-date-editor--date.el-tooltip__trigger.el-tooltip__trigger){
width: 100% !important;
}
.myDialog{
color: #26315E;
}
.dialog-footer{
display: flex;
justify-content: center;
align-items: center;
}
:deep(.el-button--large){
padding: 1.6rem 4rem;
font-size: 2rem;
color: white;
// background-color: #4088FE;
}
:deep(.el-dialog__title){
font-size: 24px;
font-family: PingFang SC-Bold, PingFang SC;
font-weight: bold;
color: #26315E;
}
:deep(.el-dialog) {
border-radius: 8px !important;
}
:deep(.el-dialog__body){
padding-top: 2.4rem;
height: 100%;
}
:deep(.el-dialog__headerbtn) {
top: 8px !important;
background: url('@/assets/img/componentImg/off.png') left no-repeat;
}
:deep(.el-dialog__headerbtn i) {
// content: '修改下面的font-size可以改變圖片的大小';
font-size: 25px;
visibility: hidden;
}
// :deep(.el-form .el-form--default .el-form--label-right .el-form--inline){
// margin: 1.8rem 0px 1.2rem !important;
// }
:deep(.el-form-item){
// margin-top: 0 !important;
}
:deep(.el-overlay){
background: rgba(0,0,0,0.8);
}
:deep(.el-input__inner){
height: 40px;
}
</style>頁(yè)面使用
import defaultDialog from "@/components/Dialog/defaultDialog.vue"
<defaultDialog
:title="EquipmentEditData.title"
@save="saveUserEdit(createFormRef)"
:show="EquipmentEditData.visible" :
noFooter=false @cancel="closeUserEdit"
@close="closeUserEdit">
<template #dia_Content>
</template>
</defaultDialog>分頁(yè)
首先創(chuàng)建個(gè)usePagination.ts
import { reactive } from "vue"
interface DefaultPaginationData {
total: number
currentPage: number
pageSizes: number[]
pageSize: number
layout: string
}
interface PaginationData {
total?: number
currentPage?: number
pageSizes?: number[]
pageSize?: number
layout?: string
}
export function usePagination(initialPaginationData: PaginationData = {}) {
/** 默認(rèn)的分頁(yè)參數(shù) */
const defaultPaginationData: DefaultPaginationData = {
total: 0,
currentPage: 1,
pageSizes: [10, 20, 50],
pageSize: 18,
layout: "prev, pager, next, jumper, total, sizes"
}
/** 合并分頁(yè)參數(shù) */
const paginationData = reactive({ ...defaultPaginationData, ...initialPaginationData })
/** 改變當(dāng)前頁(yè)碼 */
const handleCurrentChange = (value: number) => {
paginationData.currentPage = value
}
/** 改變頁(yè)面大小 */
const handleSizeChange = (value: number) => {
paginationData.pageSize = value
}
return { paginationData, handleCurrentChange, handleSizeChange }
}使用頁(yè)面
import { usePagination } from "@/hooks/usePagination"
const { paginationData, handleCurrentChange, handleSizeChange } = usePagination({ pageSize: 15, pageSizes: [15, 30, 50], layout: "prev, pager, next, jumper, total, sizes" })```
//下面是監(jiān)聽(tīng)頁(yè)面變化然后觸發(fā)查詢
watch([() => paginationData.currentPage, () => paginationData.pageSize], getTableData, { immediate: true })
//下面是頁(yè)面使用
<el-pagination background :layout="paginationData.layout" :page-sizes="paginationData.pageSizes"
:total="paginationData.total" :page-size="paginationData.pageSize"
:currentPage="paginationData.currentPage" @size-change="handleSizeChange"
@current-change="handleCurrentChange" />到此這篇關(guān)于vue3+ts封裝彈窗分頁(yè)封裝的文章就介紹到這了,更多相關(guān)vue3 ts封裝分頁(yè)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Vue源碼解析之Template轉(zhuǎn)化為AST的實(shí)現(xiàn)方法
這篇文章主要介紹了Vue源碼解析之Template轉(zhuǎn)化為AST的實(shí)現(xiàn)方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-12-12
vue在.js文件中引入store和router問(wèn)題
這篇文章主要介紹了vue在.js文件中引入store和router問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-03-03
如何使用crypto-js對(duì)文件上傳下載進(jìn)行加密處理
這篇文章主要介紹了如何使用crypto-js對(duì)文件上傳下載進(jìn)行加密處理方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-05-05
vite項(xiàng)目的根目錄中的env.d.ts類型聲明文件里要寫什么
這篇文章主要介紹了vite項(xiàng)目的根目錄中的env.d.ts類型聲明文件里要寫什么,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-08-08
vue中eslint導(dǎo)致的報(bào)錯(cuò)問(wèn)題及解決
這篇文章主要介紹了vue中eslint導(dǎo)致的報(bào)錯(cuò)問(wèn)題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-10-10
Vue3中進(jìn)行二維碼的生成與解碼實(shí)現(xiàn)詳解
這篇文章主要為大家介紹了Vue3中進(jìn)行二維碼的生成與解碼實(shí)現(xiàn)詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-03-03

