当前位置: 首页 > news >正文

【uniapp】 实现公共弹窗的封装以及调用

图例:红框区域为 “ 内容区域 ”

 一、组件

<!-- 弹窗组件 -->
<template>
<view class="add_popup" v-if="person.isShowPopup"><view class="popup_cont" :style="{width:props.width&&props.width>0?props.width+'px;':'auto;',height:props.height&&props.height>0?props.height+'px;':'auto;',background:props.bgColor+'!important;'}"><view class="popup_close" @click="cancel"></view><slot></slot></view>
</view>
</template><script setup lang="ts">
import { reactive, onMounted, watch } from 'vue'
const props = defineProps({isShow: {type: Boolean,required: true},width: {type: Number,required: false},height: {type: Number,required: false},bgColor: {type: String,required: false}
})
interface Iemit{(e:'cancelBtn'):void
}	
const emit=defineEmits<Iemit>()let person=reactive({isShowPopup:false
})watch(()=>props.isShow,(newVal)=>{person.isShowPopup=newVal
})onMounted(()=>{
})
const cancel=()=>{person.isShowPopup=!person.isShowPopupemit('cancelBtn')
}
</script><style lang="scss" scoped>
.add_popup{position: fixed;left: 0;top: 0;width: 100%;height: 100%;display: flex;flex-direction: column;justify-content: center;background: rgba(0,0,0,.4);z-index: 99;.popup_cont{text-align: center;margin: -60rpx auto 0 auto;border-radius: 20rpx;color: #3D425B;font-size: 30rpx;padding: 40rpx;display: flex;flex-direction: column;justify-content: center;position: relative;.popup_close{position: absolute;bottom: -100rpx;left: 50%;transform: translate(-50%);width: 80rpx;height: 80rpx;background: url('@/static/education/cancel.png') no-repeat;background-size: 100% 100%;}}
}
</style>

二、页面调用

<template>
<Popups :isShow="showDioUnbindMseeage" :width="260" height="auto" :bgColor="'#fff'"@cancelBtn="showDioUnbindMseeage=false"><!-- 内容区域 -->		
</Popups>
</template><script setup lang="ts">
import { ref } from 'vue'
import Popups from "@/components/popups/index.vue";const showDioUnbindMseeage = ref(false)
</script>

     希望我的愚见能够帮助你哦~,若有不足之处,还望指出,你们有更好的解决方法,欢迎大家在评论区下方留言支持,大家一起相互学习参考呀~

http://www.lryc.cn/news/144059.html

相关文章:

  • DevOps系列文章之 Python基础
  • 代码随想录第五十天
  • redis缓存雪崩、穿透、击穿解决方案
  • 基于HarmonyOS ArkUI实现七夕壁纸轮播
  • FusionAD:用于自动驾驶预测和规划任务的多模态融合
  • C# 序列化json数据,datatabel转对象
  • axios引入的详细讲解
  • 16- flask-bootstrap模板的使用
  • 机器学习-神经网络(西瓜书)
  • Apache StreamPark系列教程第二篇——项目打包和开发
  • Visual Studio 2022的MFC框架——WinMain函数
  • 9. 解谜游戏
  • fastjson利用templatesImpl链
  • OpenCV 开启O3优化
  • css background实现四角边框
  • 摆动序列【贪心算法】
  • 【Terraform学习】使用 Terraform创建 S3 存储桶事件(Terraform-AWS最佳实战学习)
  • 自定义String字符串工具类 StringUtils.java
  • mongTemplate实现group分组查询aggregation
  • 防御网络攻击风险的4个步骤
  • 相机SD卡数据丢失如何恢复?
  • Java小记-矩阵转置
  • 计网-控制平面
  • Markdown 扩展语法练习
  • ubuntu上安装boost库为SOMEIP的X86和ARM下编译做准备(编译两种版本)
  • [NSSCTF 2nd] NSS两周年纪念赛。
  • 【星戈瑞】FITC-PEG-N3在细胞示踪中的应用
  • 【Linux】【驱动】自动创建设备节点
  • 自实现getprocaddress(名称查找或者序号查找)
  • 如何DIY制作干洗店洗护小程序