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

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

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

效果图如下:

在这里插入图片描述
在这里插入图片描述

使用方法

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

如下所示:

<template>
  <div>
    <button @click="showPopup">点击显示弹框</button>
    <cc-popup v-if="isShow" :ishide="isHide" width="calc(100vw - 70px)" height="346px" radius="16rpx">
      <!-- 自定义展示内容 -->
      <view class="modelContent">
        <view style="margin-top: 6px;">{{ title }}</view>
        <view style="margin-top: 20px; color: #666666; margin: 6px 12px;">{{ content }}</view>
        <image class="imageV"></image>
        <button style="width: 80%; height: 48px;margin-top: 20px; background-color: seagreen;color: white;">确定</button>
      </view>
      <!-- 自定义关闭按钮 -->
      <view class="close" @click="hidePopup"></view>
    </cc-popup>
  </div>
</template>
export default {
  data() {
    return {
      title: '弹框标题',
      content: '这是弹框的内容',
      isShow: false,
      isHide: false, // 点击其他区域时隐藏弹框
    };
  },
  methods: {
    showPopup() {
      this.isShow = true;
    },
    hidePopup() {
      this.isHide = true;
    },
  },
};
HTML代码部分

<template>

<view class="content">

<image class="logo" src="/static/logo.png"></image>

<view class="logo" style="background-color: aquamarine;line-height: 100px;text-align: center;" @click="popupClick">点击弹框</view>

<!-- 使用组件 -->

<ccPopup :ishide='isshow' width="calc(100vw - 70px)" height="346px" radius="16rpx">

<!-- 自定义展示内容 -->

<view class="modelContent">

<view style="margin-top: 6px;">

弹框标题

</view>

<view style="margin-top: 20px; color: #666666; margin: 6px 12px;">

这是弹框内容 这是弹框内容 这是弹框内容 这是弹框内容

</view>

<image class="imageV" :src="mySrc" ></image>

</view>

<!-- 自定义关闭按钮 -->

<view class="close" @click="isshow=false"></view>

</ccPopup>

</view>

</template>

JS代码 (引入组件 填充数据)

<script>

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;

}

}

}

</script>

CSS

<style>

.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%);

}

</style>

阅读全文下载完整组件代码请关注微信公众号: 前端组件开发
在这里插入图片描述

欢迎加入我们的前端组件学习交流群,可添加群主微信,审核通过后入群。
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

前端组件开发

你的钟意将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值