@hz_yujin/vue-dialog

Vue 3 ProDialog:基于 Element Plus Dialog 全量透传,附带默认 footer / 异步确认 / 尺寸预设
Install
npm install @hz_yujin/vue-dialog
Latest Version:0.1.4
Vue:3
License:MIT
Last Updated:Sep 1, 2026
Links: npm
Maintainer: hz_yujin

@hz_yujin/vue-dialog

基于 Vue 3 + Element Plus Dialog 的弹框封装。

  • ProDialog — 全量透传 ElDialog 的 props / events / slots / expose
  • 可选默认 footer(确认 / 取消)、异步确认、尺寸预设、全局 defaults
  • 多级嵌套:子弹框写在父级插槽内自动识别,默认 append-to-body

安装

npm install @hz_yujin/vue-dialog element-plus vue

element-plus、vue 为 peerDependencies,需由宿主项目安装。

使用

import { createApp } from 'vue'
import { ProDialog } from '@hz_yujin/vue-dialog'
import '@hz_yujin/vue-dialog/style.css'

// 或全局注册
import VueDialog from '@hz_yujin/vue-dialog'
app.use(VueDialog)
<script setup lang="ts">
import { ref } from 'vue'
import { ProDialog } from '@hz_yujin/vue-dialog'
import '@hz_yujin/vue-dialog/style.css'

const visible = ref(false)

async function onConfirm() {
  await new Promise((r) => setTimeout(r, 800))
  // 返回 false 可阻止关闭
}
</script>

<template>
  <el-button type="primary" @click="visible = true">打开</el-button>

  <ProDialog
    v-model="visible"
    title="编辑"
    size="md"
    show-footer
    destroy-on-close
    @confirm="onConfirm"
  >
    <p>弹框内容</p>
  </ProDialog>
</template>

尺寸预设

size width
sm 420px
md 520px
lg 720px
xl 920px

显式传入 width 时优先生效。

多级弹框

把子 ProDialog 写在父级默认插槽内,会自动识别嵌套并默认开启 append-to-body:

<ProDialog v-model="l1" title="一级" size="lg">
  <el-button @click="l2 = true">打开二级</el-button>

  <ProDialog v-model="l2" title="二级" size="md">
    <el-button @click="l3 = true">打开三级</el-button>
    <ProDialog v-model="l3" title="三级" size="sm" />
  </ProDialog>
</ProDialog>

也可显式标记:nested(强制按嵌套处理)。业务组件内可用:

import { useProDialogNest } from '@hz_yujin/vue-dialog'

const nest = useProDialogNest() // { level, close } | null

全局默认

import { setDialogDefaults } from '@hz_yujin/vue-dialog'

setDialogDefaults({
  size: 'md',
  alignCenter: true,
  destroyOnClose: true,
  confirmText: '保存',
})

透传能力

与 Element Plus Dialog 对齐,包括但不限于:

  • props:title / width / fullscreen / draggable(默认 false) / overflow / align-center / before-close / append-to / destroy-on-close / header-class 等
  • events:open / opened / close / closed / open-auto-focus / close-auto-focus
  • slots:default / header / footer / title(兼容)
  • expose:visible / level / isNested / dialogContentRef / resetPosition / handleClose

开发

在 monorepo 根目录:

pnpm install
pnpm dev
pnpm build:dialog

Related Packages

@hz_yujin/vue2-base-dialog

Vue 2 ProDialog:基于 Element UI el-dialog 的样式包装器,统一风格并透传全部弹层...

1,035
vuedl

Vue dialog helper

17,871 29
vue-final-modal

The most powerful yet most light-weight modal library for Vue 3.

3,105,553 1,013
jenesius-vue-modal

The progressive and simple modal system for Vue.js v3

198,410 159
vodal

A vue modal with animations.

20,491 376

Version History

Version Released Vue License
0.1.4 ^3.5.0 MIT
0.1.3 ^3.5.0 MIT
0.1.1 ^3.5.0 MIT