uniapp自定义简单弹窗组件
2.0(2019-08-31)
船新版本的信息弹窗组件
插件市场地址:http://ext.dcloud.net.cn/plugin?id=672
可以弹出很多条信息,并单独控制消失时间、点击消失。
用循环来生成很多个弹窗,用this.$refs来传值,并添加数组。
1.布局
<view class="popup_list">
<view v-for="(items,index) of popup_list" :id="items.uuid" :key="items.uuid" >
<view class="mpopup" :style="{ background: items.color ,top:index*distance+50+'px'}" :class="[items.animator,items.typeClass]" @click="remove_popup(index)">
<view class="pic"><image class="icon" mode="aspectFit" :src="items.icon"></image></view>
<text class="text" :style="{ color: items.colortext }">{{ items.content }}</text>
</view>
</view>
</view>
2.js
具体流程。需要一个弹窗,基本信息传入组件,处理后添加入数组,显示弹窗,过几秒消失,从数组移除元素。
methods:{
//初始化一些数据
init:function(list){
if (list.type == 'success') {
list.icon = '../../static/xuan-popup/success.png';
list.typeClass='mpopup-success';
return list;
}
if (list.type == 'warn') {
list.icon = '../../static/xuan-popup/warn.png';
list.typeClass='mpopup-warn';
return list;
}
if (list.type == 'info') {
list.icon = '../../static/xuan-popup/info.png';
list.typeClass='mpopup-info';
return list;
}
if (list.type == 'err') {
list.icon = '../../static/xuan-popup/err.png';
list.typeClass='mpopup-err';
return list;
}
},
open:function(list){
if(!this.isdistance){this.distance=0}
let uuid=this.guid();
//初始化
let new_list=this.init(list);
new_list.uuid=uuid;
//添加进数组
this.popup_list.push(new_list);
if(typeof(new_list.isClick)!='boolean'){new_list.isClick=false;}
//可消失
if(!new_list.isClick){
this.close(uuid,new_list.timeout);
} },
close:function(uuid,timeout){
//退出动画之后,短暂延迟后移除本元素
this.fade_out_animator(uuid,timeout).then(res=>{
setTimeout(()=>{
for(let i=0;i<this.popup_list.length;i++){
if(this.popup_list[i].uuid==res){
//移除本元素
this.popup_list.splice(i,1);
this.$forceUpdate()
}
}
},250)
});
},
fade_out_animator:function(uuid,timeout){
//timeout秒后退出
if(!timeout||typeof(timeout)!='number'){timeout=3000;}
return new Promise(res=>{
setTimeout(()=>{
for(let i=0;i<this.popup_list.length;i++){
if(this.popup_list[i].uuid==uuid){
//添加退出动画
this.popup_list[i].animator='fade_Top';
res(uuid);
}
}
},timeout)
})
},
//可点击关闭的弹出框
remove_popup:function(target){
console.log(target)
if(this.popup_list[target].isClick){
this.popup_list[target].animator='fade_Top';
setTimeout(()=>{
this.popup_list.splice(target,1);
this.$forceUpdate();
},250)
}
},
//生成uuid
guid:function() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});
}
}
3.用法
import mpopup from '../../components/xuan-popup/xuan-popup.vue'
import Popup from '../../components/xuan-popup/popup.js'
export default {
components:{
mpopup
},
data() {
return {
title: 'Hello'
}
},
methods: {
// *数组形式传值
// *type,类型 success warn info err(string)
// *content,内容(string)
// *timeout,消失时间(Number)
// *isClick,是否点击消失(Boolean)
pop:function(){
this.$refs.mpopup.open(Popup.setPopup('success','我可以',false));
},
popp:function(){
this.$refs.mpopup.open(Popup.setPopup('err','错误',false));
},
poppp:function(){
this.$refs.mpopup.open(Popup.setPopup('warn','警告',1000,false));
},
popppp:function(){
//需要点击消失时,消失时间填0就好
this.$refs.mpopup.open(Popup.setPopup('info','信息',0,true));
}
}
}
1.0(2019-08-09)
前面写android混编学到了很多,没有时间全部积累起来,后面会慢慢记录的。
最近很久没有记录了,因为一个新的uniapp的项目。最近在做这个。
看了智慧团建上的弹窗很喜欢,我也要整一套(简易版)
今天兴致大发居然布了插件:http://ext.dcloud.net.cn/plugin?id=672
很简单的组件化,我们来看一看吧
一、写布局
一个大容器一张图片一个文本
<view class="content">
<view v-show="isshow" :style="{ background: color }" v-bind:class="[activeClass,animator]">
<view class="pic"><image class="icon" mode="aspectFit" :src="icon"></image></view>
<text class="text" :style="{ color: colortext }">{{ content }}</text>
</view>
</view>
css就不贴上来了,看的眼花。可以下载来看。
二、js
定义一些属性,用来决定弹什么样的窗口,显示一些什么内容
export default{
data() {
return {
icon: '',//图标
content: '',//内容
color: '',//背景颜色
colortext: '',//文本颜色
coloricon: '',//图标颜色
isshow: false,//是否显示
activeClass:'mpopup',//class
animator:'fade_Down'//动画class
};
},
//属性
props: {
//什么类型的弹窗
types: {
type: String,
value: 'success'
},
//弹窗的内容
span: {
type: String,
value: '这是一个土司'
},
//是否显示
show: {
type: String,
value: ''
}
},
computed: {
newshow() {
return this.show;
}
},
watch: {
//监听属性传入的值的变化
newshow(val) {
if (val == 'true') {
this.open();//显示弹窗
} else {
this.close();//隐藏弹窗
}
}
},
onLoad() {},
methods: {
init: function() {
this.content = this.span;
//成功类型
if (this.types == 'success') {
this.icon = '../../static/images/success.png';
this.color = '#F0F9EB';
this.colortext = '#67C23A';
this.coloricon = '#67C23A';
}
//警告类型
if (this.types == 'warn') {
this.icon = '../../static/images/warn.png';
this.color = '#FDF6EC';
this.colortext = '#E6A23C';
this.coloricon = '#E6A23C';
}
//信息类型
if (this.types == 'info') {
this.icon = '../../static/images/info.png';
this.color = '#EDF2FC';
this.colortext = '#909399';
this.coloricon = '#909399';
}
//错误类型
if (this.types == 'err') {
this.icon = '../../static/images/err.png';
this.color = '#FEF0F0';
this.colortext = '#F56C6C';
this.coloricon = '#F56C6C';
}
},
open: function() {
this.animator='fade_Down';//进入动画
this.init();
this.isshow = true;
},
close: function() {
this.animator='fade_Top';//退出动画 }
}
}
好了我们来看看怎么使用
三、使用
在需要用到的界面引入组件或者全局引入都可以
有三个属性我们需要用js来控制,每次赋值太繁琐
所以就写了个方法,每次调用就好
export default{
/*
*设置弹出框
* type:类型 span :内容 second:几秒消失
*/
setPopup:function(_this,types,span,second){
if(_this.ispop!="true"){
_this.types=types;
_this.span=span;
_this.ispop="true";
setTimeout(()=>{
_this.ispop="false";
},second)
}
}
}
引入刚才的两个js
import Popup from '@/static/js/popup.js';
import mpopup from '../../components/popup/popup.vue';
export default {
data() {
return {
ispop:"",//是否显示弹窗
types:"err",//弹窗类型
span:"这是一个土司",//弹窗内容
poptime:2000
};
},
components:{
mpopup
},
onLoad() {},
methods: {
pop:function(){
Popup.setPopup(this,"success","hello,哈喽",this.poptime);
},
popp:function(){
Popup.setPopup(this,"err","hello,哈喽",this.poptime);
},
poppp:function(){
Popup.setPopup(this,"warn","hello,哈喽",this.poptime);
},
popppp:function(){
Popup.setPopup(this,"info","hello,哈喽",this.poptime);
}
}
};
布局:
<view>
<view class="btn">
<button @click="pop()">成功</button>
<button @click="popp()">失败</button>
<button @click="poppp()">警告</button>
<button @click="popppp()">信息</button>
</view>
<mpopup :show="ispop" :types="types" :span="span"></mpopup>
</view>
这样就OK了
当时思路就是用属性来控制弹窗,组件就监听传来的属性值的变化做出改变。
用class来控制弹窗的进入和退出动画
github地址:https://github.com/steffenx/uniapp_popup
uniapp自定义简单弹窗组件的更多相关文章
- uni-app自定义Modal弹窗组件|仿ios、微信弹窗效果
介绍 uniapp自定义弹窗组件uniPop,基于uni-app开发的自定义模态弹窗|msg信息框|alert对话框|confirm确认框|toast弱提示框 支持多种动画效果.多弹窗类型ios/an ...
- 基于uniapp自定义Navbar+Tabbar组件「兼容H5+小程序+App端Nvue」
uni-app跨端自定义navbar+tabbar组件|沉浸式导航条|仿咸鱼凸起标签栏 在跨端项目开发中,uniapp是个不错的框架.采用vue.js和小程序语法结构,使得入门开发更容易.拥有非常丰富 ...
- uniapp自定义简单省市区联动组件
又双叒一个uniapp组件 最近有一个选择地址的需求,就写了一个省市区联动选择器. 选择日期使用的picker,就照着它简单的整了一个,使用网络请求城市数据,还用到了vuex组件数据共享. 本来自己整 ...
- Vue自定义Popup弹窗组件|vue仿ios、微信弹窗|vue右键弹层
基于vue.js构建的轻量级Vue移动端弹出框组件Vpopup vpopup 汇聚了有赞Vant.京东NutUI等Vue组件库的Msg消息框.Popup弹层.Dialog对话框.Toast弱提示.Ac ...
- 从零开始徒手撸一个vue的toast弹窗组件
相信普通的vue组件大家都会写,定义 -> 引入 -> 注册 -> 使用,行云流水,一气呵成,但是如果我们今天是要自定义一个弹窗组件呢? 首先,我们来分析一下弹窗组件的特性(需求): ...
- mpvue的toast弹窗组件-mptosat
几乎每个小程序都会用到的弹窗功能,弹窗是为了友好的提示用户目前小程序的状态.这样以来toast弹窗就成了小程序不可或缺的组件.mptosat用过,不赖的一款.下面记录以下使用方法: 介绍 mptoas ...
- Vue - 简单实现一个命令式弹窗组件
前言 在日常工作中弹窗组件是很常用的组件,但用得多还是别人的,空闲时间就自己来简单实现一个弹窗组件 涉及知识点:extend.$mount.$el 使用方式: this.$Confirm({ titl ...
- uniapp自定义picker城市多级联动组件
uniapp自定义picker城市多级联动组件 支持多端--h5.app.微信小程序.支付宝小程序... 支持自定义配置picker插件级数 支持无限级 注意事项:插件传入数据格式为children树 ...
- 百度智能小程序弹窗组件wcPop|智能小程序自定义model弹窗模板
百度智能小程序自定义弹窗组件wcPop|百度小程序model对话框|智能小程序弹窗界面模板 最近百度也推出了自己的智能小程序,如是就赶紧去试了下,官方提供的api还不是狠完整.而且官方提供的弹窗组件也 ...
随机推荐
- 发现一款手绘可视化神器!Python绘图还在用Matplotlib?out了 !
前言 本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. PS:如有需要Python学习资料的小伙伴可以加点击下方链接自行获取htt ...
- WinRAR代码执行漏洞复现
漏洞介绍 WinRAR 是一款流行的解压缩工具,据其官网上发布的数据,全球有超过5亿的用户在使用 2019年2月20日,安全厂商 checkpoint 发布了名为<Extracting a 19 ...
- MVC-基础01
MVC体系结构将应用程序分成三个主要组件:模型(Model).视图(View).和控制器(Controller).在ASP.NET MVC应用程序中,数据操控的逻辑包含在Models文件夹下,数据的展 ...
- XSS语义分析的阶段性总结(二)
本文首发于“合天智汇”微信公众号,作者:Kale 前言 上次分享了javascript语义分析,并且简单介绍了新型xss扫描器的一些想法,如何在不进行大量fuzz的情况下又能准确的检测出xss漏洞,这 ...
- 还学的动吗? 盘点下Vue.js 3.0.0 那些让人激动的功能
转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者. 原文出处:https://blog.bitsrc.io/vuejs-3-0-0-beta-features- ...
- Python pandas库159个常用方法使用说明
Pandas库专为数据分析而设计,它是使Python成为强大而高效的数据分析环境的重要因素. 一.Pandas数据结构 1.import pandas as pd import numpy as np ...
- 高级数据结构---赫(哈)夫曼树及java代码实现
我们经常会用到文件压缩,压缩之后文件会变小,便于传输,使用的时候又将其解压出来.为什么压缩之后会变小,而且压缩和解压也不会出错.赫夫曼编码和赫夫曼树了解一下. 赫夫曼树: 它是一种的叶子结点带有权重的 ...
- bootstrop设置背景图片自适应屏幕
如果不用bootstrop框架,想让背景图片自适应窗口大小,可以这样做: <style type="text/css"> html{height: %;} body.a ...
- How to check if directory exist using C++ and winAPI
如果看文件夹是否存在,必须看返回值是不是 INVALID_FILE_ATTRIBUTES #include <windows.h> #include <string> bool ...
- hexo-themes-setting
hexo-themes-setting hexotheme Hexo 主题配置管理 一半有几种方式, 可以删除git 单独维护 也可以使用 hexo 推荐的方式进行维护 所有需要写在主题配置文件中的配 ...