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 端無效(無鍵盤事件)。