小工具知识网

当前位置: 首页 > 行业知识 > 前端Vue自定义弹框、自定义弹框内容 alertView showModel popup 组件

行业知识

前端Vue自定义弹框、自定义弹框内容 alertView showModel popup 组件

2026-11-15 10:40:48 来源:互联网转载

随着技术的不断发展,开发复杂度也越来越高。传统的开发方式将一个系统做成了整块应用,经常出现的情况就是一个小小的改动或者一个小功能的增加可能会引起整体逻辑的修改,造成牵一发而动全身。为了解决这个问题,我们可以通过组件化开发来提高开发效率和降低维护成本。

本文将介绍一款快速实现前端Vue自定义弹框、自定义设置弹框内容的View popup组件,

效果图如下:

使用方法

首先,我们需要在HTML模板中添加一个按钮元素,用于触发弹框的显示。然后,在JavaScript部分引入我们自定义的Popup组件,并通过v-if指令控制其显示与隐藏。最后,在组件的props中定义一些属性,如isShow用于控制弹框是否显示、width、height、radius用于设置弹框的尺寸和圆角等。

如下所示:

      点击显示弹框                        {{ title }}        {{ content }}                确定                  ✕      
export default {  data() {    return {      title: '弹框标题',      content: '这是弹框的内容',      isShow: false,      isHide: false, // 点击其他区域时隐藏弹框    };  },  methods: {    showPopup() {      this.isShow = true;    },    hidePopup() {      this.isHide = true;    },  },};
HTML代码部分
点击弹框弹框标题这是弹框内容 这是弹框内容 这是弹框内容 这是弹框内容✕
JS代码 (引入组件 填充数据)
import ccPopup from '@/components/cc-popup.vue';export default {components: {ccPopup},data() {return {title: 'Hello',companyList:[{},{},{}],isshow:false,mySrc:'../../static/logo.png'}},onLoad() {},methods: {popupClick(){this.isshow = !this.isshow;}}}
CSS
.content {display: flex;flex-direction: column;}.logo {height: 200rpx;width: 200rpx;margin-top: 200rpx;margin-left: auto;margin-right: auto;margin-bottom: 50rpx;}.text-area {display: flex;justify-content: center;}.title {font-size: 36rpx;color: #8f8f94;}.modelContent {width: 100%;height: 100%;display: flex;align-items: center;flex-direction: column;justify-content: center;}.imageV {margin-top: 0px;width: calc(100vw - 100px);height: calc((100vw - 100px) * 1.027) ;}.close {width: 60rpx;height: 60rpx;color: #FFFFFF;line-height: 60rpx;text-align: center;border-radius: 50%;border: 1px solid #FFFFFF;position: relative;bottom: -10%;left: 50%;transform: translate(-50%, -50%);}

阅读全文下载完整组件代码请关注微信公众号: 前端组件开发

​

欢迎加入我们的前端组件学习交流群,可添加群主微信,审核通过后入群。

​

上一篇:怎么进行服务器负载?

下一篇:视频音乐下载方法指南