uniapp组件uni-popup弹出层的使用

 更新时间:2022年03月30日 15:59:12   作者:~疆  
弹出层组件用于弹出一个覆盖到页面上的内容,本文主要介绍了uniapp组件uni-popup弹出层的使用,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

 官方示例:uni-popup 弹出层 - DCloud 插件市场

弹出层组件用于弹出一个覆盖到页面上的内容,使用场景如:底部弹出分享弹窗、页面插屏广告等

一、基本用法

<template>
	<view>
		<button type="primary" @click="toggle('top')">顶部弹出</button>
		<button type="primary" @click="toggle('center')">居中弹出</button>
		<button type="primary" @click="toggle('bottom')">底部弹出</button>
		<uni-popup ref="popup" :type="type" :animation="false" :maskClick="true" @change="change">
			<view style="background-color: #fff;padding: 15px;">
				popup 内容,此示例没有动画效果
			</view>
		</uni-popup>
	</view>
</template>
 
<script>
export default {
	data() {
		return {
			type: 'top'
		};
	},
	methods: {
		toggle(type) {
			this.type = type;
			this.$refs['popup'].open();
		},
		change(e) {
			uni.showToast({
				title:'popup: ' + e.type + ' ,状态:'+e.show
			})
		}
	}
};
</script>

二、自定义弹出层(dialog + message) 示例

<template>
	<view>
		<button style="background-color: #4cd964;" @click="toggleMessage('success')">成功</button>
		<button style="background-color: #dd524d;" @click="toggleMessage('error')">错误</button>
		<button style="background-color: #f0ad4e;" @click="toggleMessage('warn')">警告</button>
		<button style="background-color: #909399;" @click="toggleMessage('info')">信息</button>
		<!-- 消息提示 -->
		<uni-popup ref="popupMessage" type="message">
			<uni-popup-message :type="msgType" :message="message" :duration="700" />
		</uni-popup>
		<!-- 对话框 -->
		<uni-popup ref="popupDialog" type="dialog">
			<uni-popup-dialog :type="msgType" title="通知" content="欢迎使用 uni-popup!" :before-close="true" @confirm="dialogConfirm" @close="dialogClose" />
		</uni-popup>
	</view>
</template>
 
<script>
export default {
	data() {
		return {
			msgType: 'success',
			message: '这是一条成功消息提示'
		};
	},
	methods: {
		toggleMessage(type) {
			this.msgType = type;
			switch (type) {
				case 'success':
					this.message = '这是一条成功消息提示';
					break;
				case 'warn':
					this.message = '这是一条警告消息提示';
					break;
				case 'info':
					this.message = '这是一条消息提示';
					break;
				case 'error':
					this.message = '这是一条错误消息提示';
					break;
			}
			this.$refs['popupDialog'].open();
		},
		dialogConfirm() {
			this.$refs.popupMessage.open();
			
			this.$refs['popupDialog'].close();
		},
		dialogClose() {
			this.msgType = 'info';
			this.message = '点击了对话框的取消按钮';
			this.$refs.popupMessage.open();
			
			this.$refs.popupDialog.close();
		}
	}
};
</script>

三、提交信息 (input + 延迟关闭)

<template>
	<view>
		输入内容:{{value}}
		<button type="primary" @click="confirmDialog">输入对话框</button>
		<uni-popup ref="dialogInput" type="dialog">
			<uni-popup-dialog mode="input" title="输入内容" value="对话框预置提示内容!" placeholder="请输入内容" @confirm="dialogInputConfirm"/>
		</uni-popup>
	</view>
</template>
 
<script>
	export default {
		data() {
			return {
				msgType: 'success',
				value: '默认输入的内容'
			}
		},
		methods: {
			confirmDialog() {
				this.$refs['dialogInput'].open()
			},
			dialogConfirm(done) {
				this.$refs['popupMessage'].open()
			},
			dialogInputConfirm( val) {
				uni.showLoading({
					title: '1秒后会关闭'
				})
				this.value = val
				setTimeout(() => {
					uni.hideLoading()
				}, 1000)
			}
		},
	}
</script>

四、底部分享示例

<template>
	<view>
		<button type="primary" @click="confirmShare">分享模版示例</button>
		<uni-popup ref="popupShare" type="share">
			<uni-popup-share title="分享到" @select="select"></uni-popup-share>
		</uni-popup>
	</view>
</template>
 
<script>
	export default {
		data() {
			return {
			}
		},
		methods: {
			confirmShare() {
				this.$refs.popupShare.open()
			},
			select(e) {
				uni.showToast({
					title: `您选择了第${e.index+1}项:${e.item.text}`,
					icon: 'none'
				})
			}
		},
	}
</script>

 到此这篇关于uniapp组件uni-popup弹出层的使用的文章就介绍到这了,更多相关uniapp uni-popup弹出层内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • JavaScript网格中的最小路径讲解

    JavaScript网格中的最小路径讲解

    这篇文章主要介绍了JavaScript网格中的最小路径讲解,所有路径经过的单元格的 值之和 加上 所有移动的 代价之和 。从 第一行 任意单元格出发,返回到达 最后一行 任意单元格的最小路径代价
    2022-06-06
  • 更优雅的微信小程序骨架屏实现详解

    更优雅的微信小程序骨架屏实现详解

    这篇文章主要介绍了更优雅的微信小程序骨架屏实现详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
    2019-08-08
  • javascript textarea光标定位方法(兼容IE和FF)

    javascript textarea光标定位方法(兼容IE和FF)

    主要是实现textarea中光标的定位方法,考虑到多浏览器的兼容性,需要的朋友可以参考下。
    2011-03-03
  • JavaScript自动内存管理与垃圾回收策略详细分析讲解

    JavaScript自动内存管理与垃圾回收策略详细分析讲解

    JS的垃圾回收机制是为了以防内存泄漏,内存泄漏的含义就是当已经不需要某块内存时这块内存还存在着,垃圾回收机制就是间歇的不定期的寻找到不再使用的变量,并释放掉它们所指向的内存。因为内存的大小是有限的,所以当内存不再需要的时候,我们需要对其进行释放
    2023-01-01
  • 24个ES6方法解决JS实际开发问题(小结)

    24个ES6方法解决JS实际开发问题(小结)

    这篇文章主要介绍了24个ES6方法解决JS实际开发问题,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-05-05
  • js图片无缝滚动插件使用详解

    js图片无缝滚动插件使用详解

    这篇文章主要为大家详细介绍了js图片无缝滚动插件的使用方法,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2019-07-07
  • JavaScript模块随意拖动示例代码

    JavaScript模块随意拖动示例代码

    这篇文章主要介绍了JavaScript模块随意拖动的具体实现,需要的朋友可以参考下
    2014-05-05
  • js类式继承与原型式继承详解

    js类式继承与原型式继承详解

    这篇文章主要为大家详细介绍了js类式继承与原型式继承,感兴趣的小伙伴们可以参考一下
    2016-04-04
  • 微信小程序设置滚动条过程详解

    微信小程序设置滚动条过程详解

    这篇文章主要介绍了微信小程序设置滚动条过程详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
    2019-07-07
  • 微信小程序自定义modal弹窗组件的方法详解

    微信小程序自定义modal弹窗组件的方法详解

    这篇文章主要给大家介绍了关于微信小程序自定义modal弹窗组件的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-12-12

最新评论