Skip to content

Dialog 对话框 ​

基础用法 ​

vue
<template>
  <lh-button @click="visible = true">打开对话框</lh-button>

  <lh-dialog v-model="visible" title="标题" width="80%">
    <view>这是对话框内容</view>
    <template #footer>
      <lh-button @click="visible = false">取消</lh-button>
      <lh-button type="primary" @click="visible = false">确定</lh-button>
    </template>
  </lh-dialog>
</template>

<script setup lang="ts">
import { ref } from 'vue'
const visible = ref(false)
</script>

定位 ​

vue
<template>
  <lh-dialog v-model="visible" position="bottom" title="底部弹层">
    <view>底部内容</view>
  </lh-dialog>

  <lh-dialog v-model="visible" fullscreen title="全屏">
    <view>全屏内容</view>
  </lh-dialog>
</template>

底部弹层会自动带 env(safe-area-inset-bottom) 适配全面屏。

Props ​

属性说明类型默认值
modelValue (v-model)是否显示booleanfalse
title标题string—
width宽度string | number—
top顶部距离string | number—
fullscreen全屏booleanfalse
position定位'center' | 'top' | 'bottom''center'
closeOnClickModal点击遮罩关闭booleantrue
closeOnPressEscapeEsc 关闭(MP 无键盘事件,无效)booleantrue
lockScroll锁定背景滚动(仅 H5 有效)booleantrue
zIndex层级;不传时自增分配number—
customClass自定义类名string—
themeVars组件级主题变量Record<string, string>—
sx快速布局属性LhSxProps—

Slots ​

插槽说明
default内容
footer底部按钮区

Events ​

事件说明回调参数
update:modelValue显隐变化(visible: boolean)
open打开—
close关闭—

与 Vue3 版的差异

  • 弹层挂载走 root-portal(H5 是 teleport,MP 是 root-portal 或页内 fixed 降级)。
  • focus-trap 在 MP 端不可用:由 LH_IS_H5 编译期守卫直接返回 false,不调用 focus-trap。
  • lockScroll 在 MP 端无效:小程序无 body 滚动锁定,由遮罩拦截点击兜底。
  • closeOnPressEscape 在 MP 端无效(无键盘事件)。