Vue3弹窗遮罩模板

自用留档(图标引的阿里巴巴图标库)

子组件:弹窗+遮罩

<template>
  <div class="talent-report">
    <div class="context">
      <div class="text-box">
        <!-- 关闭按钮 -->
        <i @click="boxClose" class="iconfont iconguanbi2fill"></i>

        <!-- 弹窗里的内容 -->
        <div class="box">

        </div>
      </div>
    </div>

    <div @click="boxClose" class="mark"></div>
  </div>
</template>
 
<script setup>
import { ref, defineEmits } from "vue";

const emit = defineEmits(["boxClose"]);

const boxClose = () => {
  emit("boxClose", false);
};
</script>
 
<style lang="scss" scoped>
.talent-report {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 400;
  font-size: 12px;
  color: $color;
  > .context {
    position: absolute;
    z-index: 400;
    left: calc(50% - 720px / 2);
    > .text-box {
      position: relative;
      top: calc(50vh - 500px / 2);
      // margin: 120px auto 0;
      width: 720px;
      height: 500px;
      background-color: #fff;
      > i {
        position: absolute;
        color: #aaa;
        right: -40px;
        top: -5px;
        font-size: 35px;
        cursor: pointer;
      }
      >.box{}
    }
  }
  > .mark {
    position: fixed;
    width: 100vw;
    height: 100vh;
    background-color: rgba(43, 43, 43, 0.7215686275);
  }
}
</style>

父组件使用

<!-- 个人认证弹窗 -->
    <PersonalAuthentica v-show="boxChange" @boxClose="boxClose" />





import PersonalAuthentica from "./PersonalAuthentica.vue";



// 个人认证弹窗状态
const boxChange = ref(false);
const boxClose = (e) => {
  console.log(e);
  boxChange.value = false;
};

子组件自定义高度后 锁定父元素(原整体页面)滚动

// 抽屉弹窗-关闭
const boxChange = ref(false);
const boxClose = (e) => {
  boxChange.value = false;
  let m = function (e) {
    e.preventDefault();
  };
  document.body.style.overflow = ""; //出现滚动条
  document.removeEventListener("touchmove", m, { passive: true });
};
// 抽屉弹窗-打开
const boxOpen = () => {
  boxChange.value = true;
  let m = function (e) {
    e.preventDefault();
  };
  document.body.style.overflow = "hidden";
  document.addEventListener("touchmove", m, { passive: false }); //禁止页面滑动
};

页面滚动条样式

::-webkit-scrollbar {
        //滚动条整体
        width: 1px;
        opacity: 0;
      }

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
A: 为了编写一个炫酷的Vue3弹窗组件,我们需要在应用程序中使用Vue3,同时也需要用到Vue3的Composition API。下面是一个简单的示例: 1. 创建一个单文件组件(popup.vue),其中包含一个触发弹窗的按钮和弹窗本身。 ```html <template> <div> <button @click="showPopup">触发弹窗</button> <div v-if="isPopupVisible" class="popup"> <h2 class="popup__title">{{title}}</h2> <div class="popup__content"> <slot></slot> </div> <button class="popup__close" @click="closePopup">关闭</button> </div> </div> </template> <script> import { reactive } from 'vue'; export default { name: 'Popup', props: { title: { type: String, default: '弹窗' } }, setup(props, { emit }) { const state = reactive({ isPopupVisible: false }); const showPopup = () => { state.isPopupVisible = true; }; const closePopup = () => { state.isPopupVisible = false; emit('close'); }; return { state, showPopup, closePopup }; } }; </script> <style scoped> .popup { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background-color: white; padding: 1rem; } .popup__title { margin-top: 0; } .popup__close { margin-top: 1rem; } </style> ``` 2. 在应用程序中使用该组件: ```html <template> <div> <Popup title="弹窗1"> <p>这是弹窗1的内容。</p> </Popup> <Popup title="弹窗2"> <p>这是弹窗2的内容。</p> </Popup> </div> </template> <script> import Popup from './popup.vue'; export default { name: 'App', components: { Popup } }; </script> ``` 现在,我们已经编写了一个简单的Vue3弹窗组件。我们可以在父组件中使用它,创建多个弹窗实例,并在子组件中设置不同的标题和内容。我们还可以通过事件监听器关闭弹窗,以及使用动画和其他效果来增强组件的外观和功能。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值