mask.vue 1004 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <template>
  2. <div class="mask" @click.self="toggleView" v-if="show">
  3. <slot />
  4. </div>
  5. </template>
  6. <script lang="ts">
  7. import { defineComponent, reactive, watchEffect, toRefs } from 'vue';
  8. export default defineComponent({
  9. props: {
  10. show: {
  11. type: Boolean,
  12. default: () => false,
  13. },
  14. },
  15. setup(props:any, ctx:any) {
  16. const data = reactive({
  17. show: false,
  18. });
  19. watchEffect(() => {
  20. data.show = props.show;
  21. });
  22. const toggleView = () => {
  23. data.show = !data.show;
  24. ctx.emit('update:show', data.show);
  25. };
  26. return {
  27. ...toRefs(data),
  28. toggleView,
  29. };
  30. },
  31. });
  32. </script>
  33. <style lang="scss" scoped>
  34. @import url('../../styles/common.scss');
  35. @import url('../../styles/icon.scss');
  36. .mask {
  37. position: fixed;
  38. width: 100vw;
  39. height: 100vh;
  40. left: 0;
  41. top: 0;
  42. z-index: 99;
  43. background: rgba(#000000, 0.5);
  44. display: flex;
  45. justify-content: center;
  46. align-items: center;
  47. main {
  48. position: relative;
  49. }
  50. }
  51. </style>