uni-app自定义Modal弹窗组件|仿ios、微信弹窗效果
介绍
uniapp自定义弹窗组件uniPop,基于uni-app开发的自定义模态弹窗|msg信息框|alert对话框|confirm确认框|toast弱提示框
支持多种动画效果、多弹窗类型ios/android、可以自定义弹窗样式/自定义多按钮及事件/弹窗显示位置、自动关闭秒数、遮罩层透明度及点击遮罩是否关闭
H5/小程序/App三端效果如下,亲测多端效果兼容性一致。(后续大图均展示App端)

用法
◆ 弹窗uniPop.vue组件两种引入方式
1、在main.js里引入全局组件
import uniPop from './components/uniPop/uniPop.vue'
Vue.component('uni-pop', uniPop)
2、在相应页面引入组件
import uniPop from './components/uniPop/uniPop.vue'
export default {
data() {
return {
...
}
},
components:{
uniPop
},
...
}
<template>
<view class="container">
... <!-- 弹窗模板 -->
<uni-pop ref="uniPop"></uni-pop>
</view>
</template>
- msg信息框效果

this.$refs.uniPop.show({
content: 'msg消息提示框(5s后窗口关闭)',
shade: true,
shadeClose: false,
time: 5,
anim: 'fadeIn',
})
- toast弱提示信息 - 支持success / info / error / loading四种图标

this.$refs.uniPop.show({
skin: 'toast',
content: 'loading',
icon: 'loading', //success | info | error | loading
shade: false,
time: 3
})
- ios弹窗效果

let uniPop = this.$refs.uniPop
uniPop.show({
skin: 'ios',
title: '开启新邮件提醒',
content: '为了保证新邮件能及时收到提醒,请前往系统 [设置] - [电池] 中关闭应用锁屏清理。',
shadeClose: false, btns: [
{
text: '取消',
style: 'color: #2a83f2',
onTap() {
uniPop.close();
}
},
{
text: '前往设置',
style: 'color: #2a83f2',
onTap() {
console.log('您点击了前往设置!');
}
}
]
})
调用方式如上,只是传入参数不一样,下面就不一 一展示了










◆ uniapp自定义模板template
/**
* @tpl uni-app自定义弹窗组件 - uniPop.vue
* @author andy by 2019-09-20
* @about Q:282310962 wx:xy190310
*/ <template>
<view v-if="opts.isVisible" class="uniPop" :class="opts.isCloseCls">
<view class="unipop__ui_panel">
<view v-if="opts.shade" class="unipop__ui_mask" @tap="shadeTaped"></view>
<view class="unipop__ui_main">
<view class="unipop__ui_child" :style="opts.style">
<!-- 标题 -->
<view v-if="opts.title" class="unipop__ui_tit">{{opts.title}}</view>
<!-- 内容 -->
<view v-if="opts.content" class="unipop__ui_cnt" :style="opts.contentStyle">
{{opts.content}}
</view>
<view v-if="opts.btns" class="unipop__ui_btns">
<text v-for="(item,index) in opts.btns" :key="index" class="btn" :style="item.style" @tap="btnTaped(item)">{{item.text}}</text>
</view>
</view>
<!-- xclose -->
<view v-if="opts.xclose" class="unipop__xclose" @tap="close"></view>
</view>
</view>
</view>
</template>
◆ 默认参数配置
data() {
return {
defaultOptions: {
isVisible: false, //是否显示弹窗
title: '', //标题
content: '', //内容
contentStyle: '', //内容样式
style: null, //自定义弹窗样式
skin: '', //弹窗风格
icon: '', //弹窗图标
xclose: false, //自定义关闭按钮
shade: true, //遮罩层
shadeClose: true, //点击遮罩关闭
opacity: '', //遮罩透明度
time: 0, //自动关闭秒数
end: null, //销毁弹窗回调函数
anim: 'scaleIn', //弹窗动画 scaleIn(默认) | fadeIn | shake | top | right | bottom | left
position: '', //弹窗位置 top | right | bottom | left
btns: null, //弹窗按钮
},
opts: {},
timer: null
}
},
◆ 通过Object.assign函数进行参数合并处理
methods: {
// 显示弹窗事件(处理传参)
show(args) {
this.opts = Object.assign({}, this.defaultOptions, args, {isVisible: true})
// console.log(this.opts)
// 自动关闭
if(this.opts.time) {
this.timer = setTimeout(() => {
this.close()
}, this.opts.time * 1000)
}
},
...
}
好了,uni-app自定义弹窗组件介绍就到这里,希望能喜欢
uni-app自定义Modal弹窗组件|仿ios、微信弹窗效果的更多相关文章
- react-native自定义Modal模态框|仿ios、微信弹窗RN版
前序 纵观每个优质项目,无论web端还是native原生应用开发,弹窗都是不可忽视的一环,能很大程度上直接决定用户体验.如:微信.支付宝.ios都有很成熟的一套弹窗UI展示场景. 最近一直沉迷在rea ...
- Taro自定义Modal对话框组件|taro仿微信、android弹窗
基于Taro多端实践TaroPop:自定义模态框|dialog对话框|msg消息框|Toast提示 taro自定义弹出框支持编译到多端H5/小程序/ReactNative,还可以自定义弹窗类型/弹窗样 ...
- 自己定义控件:onDraw 方法实现仿 iOS 的开关效果
概述 本文主要解说怎样在 Android 下实现高仿 iOS 的开关按钮,并不是是在 Android 自带的 ToggleButton 上改动,而是使用 API 提供的 onDraw.onMeasur ...
- Android系统下用js自定义gesture事件(仿ios实现移动端事件一致)
.katex { display: inline-block; text-align: initial; } .katex { font-family: Consolas, Inconsolata, ...
- Android -- 仿ios上下反弹效果
1,前几天在一个app上看到了滑动反弹效果,觉得这个效果挺不错的,然后想自己来实现一下,在网上查了一下基本上都是大致的说了下思路,自己看了一下,决定把实现的思路来详细的写下来,先看一下我们实现的效果吧 ...
- [转]ANDROID仿IOS微信滑动删除_SWIPELISTVIEW左滑删除例子
转载:http://dwtedx.sinaapp.com/itshare_290.html 本例子实现了滑动删除ListView的Itemdemo的效果.大家都知道.这种创意是来源于IOS的.左滑删除 ...
- [Android-2A] -仿IOS微信滑动删除_SwipeListview左滑删除例子
https://yunpan.cn/cueUIQkRafQrH (提取码:7ec1) 关于这样类似的例子网上的代码很多,最近发现这个例子里的代码在开发中会遇到一系列的问题.比如ListView的OnI ...
- 在uwp仿IOS的页面切换效果
有时候我们需要编写一些迎合IOS用户使用习惯的uwp应用,我在这里整理一下仿IOS页面切换效果的代码. 先分析IOS的页面切换.用户使用左右滑动方式进行前进和后退,播放类似于FlipView的切换动画 ...
- Vue自定义Popup弹窗组件|vue仿ios、微信弹窗|vue右键弹层
基于vue.js构建的轻量级Vue移动端弹出框组件Vpopup vpopup 汇聚了有赞Vant.京东NutUI等Vue组件库的Msg消息框.Popup弹层.Dialog对话框.Toast弱提示.Ac ...
随机推荐
- SpringBoot2.0 整合 SpringSecurity 框架,实现用户权限安全管理
本文源码:GitHub·点这里 || GitEE·点这里 一.Security简介 1.基础概念 Spring Security是一个能够为基于Spring的企业应用系统提供声明式的安全访问控制解决方 ...
- C#以对象为成员的例子
using System; using System.Collections.Generic; using System.Text; namespace test { class Program { ...
- Spring Boot 2 单元测试
开发环境:IntelliJ IDEA 2019.2.2Spring Boot版本:2.1.8 IDEA新建一个Spring Boot项目后,pom.xml默认包含了Web应用和单元测试两个依赖包.如下 ...
- Android Studio添加文件注释头模板集合
Android Studio中设置方式 File -> Settings -> Editor -> File and Code Templates -> 右侧File标签 -& ...
- 关于xshell连接limux界面按退格键不正常的问题
这个问题通过修改xshell终端属性可以解决,步骤如下: "文件" -> "属性" -> "终端" -> "键盘 ...
- Octave中的矩阵常用操作2
sum(a):矩阵里的数据求和prod(a):乘积floor(a):向上取整ceil(a):向下取整max(A,[],1):取每一列的最大值max(A,[],2):取每一行的最大值max(max(A) ...
- 201871010113-刘兴瑞《面向对象程序设计(java)》第十一周学习总结
项目 内容 这个作业属于哪个课程 <任课教师博客主页链接> https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 <作业链接地址>htt ...
- nginx学习(四):nginx处理web请求机制
worker抢占机制 如下图所示,如果有一个请求,各个work进程会进行争锁.谁抢到是谁的.需要注意Nginx 所有worker进程协同工作的关键(共享内存). [accept_mutex的介绍] 当 ...
- js正则高级函数(replace,matchAll用法),实现正则替换(实测很有效)
有这么一个文档,这是在PC端显示的效果,如果放在移动端,会发现字体大小是非常大的,那么现在想让这个字体在移动端能按照某个比例缩小,后台返回的数据格式是: <html> <head&g ...
- A1100 Mars Numbers (20 分)
一.技术总结 这一题可以使用map进行想打印存储,因为数据量不是很大,最后直接输出.但是还是觉得没有必要. 主要考虑两个问题,首先是数字转化为字符串,实质就是进制转化,但是有点不同,如果十位有数字,个 ...