uniapp中组件库Mask 遮罩层 的使用方法

目录

#平台差异说明

#基本使用

#嵌入内容

#遮罩样式

#API

#Props

#Events

#Slot


创建一个遮罩层,用于强调特定的页面元素,并阻止用户对遮罩下层的内容进行操作,一般用于弹窗场景

#平台差异说明

App H5 微信小程序 支付宝小程序 百度小程序 头条小程序 QQ小程序

#基本使用

  • 通过show参数配置是否显示遮罩

  • 遮罩被点击时,会发送一个click事件,如不需要此事件,请设置mask-click-able参数为false

    <template> <u-mask :show="show" @click="show = false"></u-mask> </template> <script> export default { data() { return { show: true } } } </script>

#嵌入内容

通过默认插槽可以在遮罩层上嵌入任意内容

注意:如果不想让slot插槽内容的点击事件冒泡到遮罩,请给指定元素添加上@tap.stop

复制代码
<template>
	<u-mask :show="show" @click="show = false">
		<view class="warp">
			<view class="rect" @tap.stop></view>
		</view>
	</u-mask>
</template>

<script>
	export default {
		data() {
			return {
				show: true
			}
		}
	}
</script>

<style scoped>
	.warp {
		display: flex;
		align-items: center;
		justify-content: center;
		height: 100%;
	}

	.rect {
		width: 120px;
		height: 120px;
		background-color: #fff;
	}
</style>

#遮罩样式

  • 通过duration设置遮罩淡入淡出的时长,单位ms

  • 通过zoom设置遮罩淡入淡出时是否带有轻微的缩放效果,内部通过transform: scale(1.2, 1.2)实现

  • 通过custom-style传入一个对象,自定义样式,如"{backgroundColor: 'red', color: 'blue'}"

    <u-mask :show="show" :duration="400" :zoom="true" :custom-style="{background: 'rgba(0, 0, 0, 0.5)'}"></u-mask>

#API

#Props

参数 说明 类型 默认值 可选值
show 是否显示遮罩 Boolean false true
z-index z-index 层级 String | Number 10070 -
custom-style 自定义样式对象,见上方说明 Object - -
duration 动画时长,单位毫秒 String | Number 300 -
zoom 是否使用scale对遮罩进行缩放 Boolean true false
mask-click-able 遮罩是否可点击,为false时点击不会发送click事件 Boolean true false

#Events

事件名 说明 回调参数
click mask-click-abletrue时,点击遮罩发送此事件 -

#Slot

名称 说明
default 默认插槽,用于在遮罩层上方嵌入内容
相关推荐
1登峰造极1 天前
uniapp 运行安卓报错reportJSException >>>> exception function:createInstanceContext, exception:white screen
android·java·uni-app
滴水未满1 天前
uniapp的组件
uni-app
object not found1 天前
基于uniapp开发小程序自定义顶部导航栏状态栏标题栏
前端·javascript·小程序·uni-app
总爱写点小BUG1 天前
VU-Icons:打造极致体验的 Vue3 & UniApp 双端 SVG 图标库
uni-app·vue·组件库·图标组件库
咸虾米_1 天前
uniapp引入iconfont字体图标在微信小程序中适用
微信小程序·小程序·uni-app
知兀2 天前
【uniapp/vue3+ts/js】eslint9+prettier+husky+lint-staged
前端·javascript·uni-app
2501_915918412 天前
如何在iPad上找到并打开文件夹的完整指南
android·ios·小程序·uni-app·iphone·webview·ipad
weixin_638303112 天前
uniapp组合式和选项式
javascript·vue.js·uni-app
木子啊2 天前
UniApp Base64上传终极解决方案
uni-app·base64·base64转图片·base64上传
2501_915918412 天前
Wireshark、Fiddler、Charles抓包工具详细使用指南
android·ios·小程序·https·uni-app·iphone·webview