Skip to content

Overlay 遮罩层

创建一个遮罩层,用于强调特定的页面元素,并阻止用户进行其他操作。

导入

js
import Overlay from '@/components/dialog/Overlay.vue';

使用方法

基础用法

基础遮罩层可以用于阻止用户操作,通常与其他组件结合使用。

vue
<template>
  <Overlay
    :show="showProp1"
    @close="() => showProp1 = false"
  />
</template>

<script setup lang="ts">
import { ref } from 'vue';
import Overlay from '@/components/dialog/Overlay.vue';

const showProp1 = ref(false);
</script>

嵌入内容

遮罩层中可以嵌入自定义内容,如图片、表单等。

vue
<template>
  <Overlay
    :show="showProp2"
    @close="() => showProp2 = false"
  >
    <FlexCol center>
      <Image
        :src="TestImage"
        :width="700"
        :height="800"
      />
    </FlexCol>
  </Overlay>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import Overlay from '@/components/dialog/Overlay.vue';
import FlexCol from '@/components/layout/FlexCol.vue';
import Image from '@/components/basic/Image.vue';
import TestImage from '/static/images/test/testDialog.png';

const showProp2 = ref(false);
</script>

自定义背景颜色

可以通过 maskColor 属性自定义遮罩层的背景颜色。

vue
<template>
  <Overlay
    :show="showProp3"
    maskColor="rgba(2, 14, 244, 0.3)"
    @close="() => showProp3 = false"
  >
    <FlexCol backgroundColor="white" :width="200" :height="200" />
  </Overlay>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import Overlay from '@/components/dialog/Overlay.vue';
import FlexCol from '@/components/layout/FlexCol.vue';

const showProp3 = ref(false);
</script>

API 参考

Overlay

遮罩层组件,基于 Popup 组件封装。

Props

名称说明类型必填默认值
show是否显示当前遮罩层boolean-
maskColor遮罩的颜色string-'background.mask'
mask是否显示遮罩,默认是boolean-true
backgroundColor弹出层背景颜色,默认是透明string-'transparent'
duration指定弹出层动画时长,毫秒number-230
closeable是否可以点击遮罩关闭当前遮罩层boolean-true
margin对话框偏移边距,默认为0,0,0,0number[]-[0,0,0,0]
inset强制设置整体边距(包括遮罩层)(number|string|undefined)[]-[undefined,undefined,undefined,undefined]
safeArea从侧边弹出时,是否自动设置安全区boolean-true
innerStyle指定当前弹出层的特殊样式ViewStyle--
size指定弹出层从侧边弹出的高度或宽度string|number-'30%'

Slots

名称说明
default默认插槽,用于插入遮罩层中的内容

Events

名称说明参数
close点击遮罩层时触发的事件

主题变量

名称类型默认值说明
PopupMaskBackgroundColorstringrgba(0, 0, 0, 0.5)遮罩层背景颜色