uni-popup(实现自定义弹窗提示、交互)

一般提示框的样式,一般由设计稿而定,如果用uniapp的showmodel,那个并不能满足我们需要的自定义样式,所以最好的方式是我们自己封装一个!(想什么样就什么样)!

一、页面效果

二、使用uni-popup

直接看代码吧!

html 复制代码
<template>
  <view>
    <uni-popup ref="tipPopup" type="center" :is-mask-click="true">
      <view class="pop">
        <view class="title">
          温馨提示
        </view>
        <!-- 提示icon -->
        <view class="tip-img">
          <image src="../../static/image/tip/tip-icon.png" mode=""></image>
        </view>
        <view class="tip-info">
          {{title}}
        </view>
        <view class="sure" @click="sure">
          确定
        </view>
      </view>
    </uni-popup>
  </view>
</template>

<script>
  export default {
    name:"showTip",
    props:["title"],
    data() {
      return {
        
      };
    },
    methods: {
      open() {
        this.$refs.tipPopup.open()
      },
      sure() {
        this.$refs.tipPopup.close()
      }
    }
  }
</script>

<style scoped>
.pop {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%,-50%);
    background-color: #fff;
    border-radius: 16rpx;
    height: 576rpx;
    z-index: 99;
    width: 640rpx;
    padding: 30rpx 0;
  }
  .title {
    text-align: center;
    font-size: 34rpx;
    font-weight: 500;
    margin-top: 38rpx;
  }
  .tip-img {
    margin: 0 auto;
    width: 296rpx;
    height: 204rpx;
    margin-top: 64rpx;
  }
  .tip-img image {
    width: 100%;
    height: 100%;
  }
  .tip-info {
    padding: 0 30rpx;
    font-size: 34rpx;
    color: #666;
    margin-top: 32rpx;
    margin-bottom: 64rpx;
    text-align: center;
  }
  .sure {
    width: 100%;
    border-top: 1rpx solid #d1d1d1;
    height: 112rpx;
    text-align: center;
    line-height: 112rpx;
    color: #02A53C;
    font-size: 34rpx;
    font-weight: 500;
  }
</style>

我这里是把他封装成组件,一般这种交互性的,用得到的地方比较多,也建议封装成组件进行使用。

三、在页面中使用

主要是这俩个方法控制关和开。

导入和使用:

html 复制代码
<!-- 错误提示弹窗 -->
    <showTip ref="showtip" :title="tiptitle"></showTip>
html 复制代码
import showTip from "/components/showTip/showTip.vue";

声明:

在data中声明数据:

html 复制代码
privacyVisible: false,
tiptitle: "错误",

声明组件:

html 复制代码
components: {
      showTip
    },

然后就可以使用了:

比如:

顺便把错误的提示文字传进去组件,组件通过props接收直接使用。

根据这个规则,就可以在此基础上封装成自己需要的样式就可以了!

相关推荐
GuWenyue40 分钟前
昵称限 20 字,8 个 emoji 却超长:一个「字」在系统里有四种长度
javascript·数据库·后端
CV-deeplearning1 小时前
Chrome DevTools实战
前端·agent·chrome devtools·mcp
xurileidian1 小时前
第 30 篇 · 边玩边学Python · 猜数字小游戏 把判断循环异常串起来
前端·python·算法
前端精髓1 小时前
三种方式实现 Agent 工具调用:OpenAI、LangChain 与 LangGraph
前端·数据库·langchain
国科安芯2 小时前
光链路捕获的那一刻:商业激光通信终端捕获跟踪伺服与探测前端的低噪声供电
前端·网络·卫星·电源芯片·抗辐照芯片·在轨
一铭111992 小时前
微信小程序可视化搭建实战:模板、组件与发布验收
前端·低代码·微信小程序·小程序·页面设计·可视化搭建·发布验收
LabVIEW开发2 小时前
LabVIEW 2025 新特性盘点:这几个改进,值得你认真看一遍
前端·labview
画中有画4 小时前
自动化脚本中使用RSA
前端·javascript·自动化
要吃这碗饭4 小时前
Codex failed to revert changes怎么办?2026年4类成因与恢复指南
前端·人工智能
陈随易5 小时前
豆包工作和WorkBuddy性价比评测
前端·后端