Mask

0.3.9

Mask 遮罩组件

>{}
<template>
  <div>
    <Button @click="btnEvent">显示遮罩</Button>
    <div v-if="isShow" :style="styled">Heelo ! 我是Mask容器,点外层关闭</div>
    <Mask v-if="isShow" opacity="0.8" @onEvent="onMaskEvent" />
  </div>
</template>

<script>
export default {
  setup() {
    const { ref } = window.$plus.vue;

    const isShow = ref(false);

    const styled = ref('');

    const btnEvent = () => {
      isShow.value = true;
    };

    /** 遮罩层 触发事件 */
    const onMaskEvent = (resp) => {
      console.log('onMaskEvent', resp);
      // 取出遮罩坐标,计算容器的坐标
      switch (resp.cmd) {
        case 'zIndex':
          // 设置容器内的坐标
          styled.value =
            'position: absolute;background-color: #fff;padding:2rem; z-index:' +
            (resp.zIndex + 1);
          break;
        case 'click':
          // 遮罩点击事件,可关闭自己
          isShow.value = false;
          break;
      }
    };

    return { isShow, btnEvent, onMaskEvent, styled };
  },
};
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

Mask props

属性说明类型默认值
named组件命名,可自定义区分事件Stringmask
opacity透明度 0.5Stringnull

Mask events

事件名说明返回值
onEvent监听组件回调触发事件json
{
  "cmd": "触发事件",
  "named": "组件命名",
  "zIndex": "纵向坐标",
  "event": "触发对象"
}
1
2
3
4
5
6

Last Updated: