uni-app:uView弹出层的使用

一、简介

uni搭配uView框架,uView框架弹出层,网址:https://www.uviewui.com/

(一) 页面使用案例演示

1.点击按钮
<view class="qrcode" @click="open()">
	<image src="/static/images/qrcode.png" mode="aspectFit"></image>
</view>
2.弹出层【绑定一个布尔值的变量控制弹出层的打开和收起,这里设置的show】
<!-- 二维码的弹出层 -->
<u-popup :show="show" mask="true" mode="center">
	<view>
	<image src="../../static/images/close.png" mode="aspectFill" @click="close()" ></image>
		//这里面存放弹出的内容
	</view>
</u-popup>
3.open弹出层打开打开调用的方法
methods: {
	open() {
		this.show = true;
	},
	close() {
		this.show = false;
	}
}
4.其他参考

在这里插入图片描述

(二) 封装组件案例演示

1.点击按钮
<view class="qrcode" @click="open()">
	<image :src="$common.image('/static/images/qrcode.png')" mode="aspectFit" class="qrcodeSmall"></image>
</view>
2.封装弹出层组件

在这里插入图片描述

<template>
	<view>
		<!-- 二维码的弹出层 -->
		<u-popup :show="show" mask="true" mode="center" width="689rpx" height="689rpx">
			//这里面放内容
			//关闭按钮
			<image src="/static/images/close.png" mode="aspectFill" @click="close()" ></image>
		</u-popup>
	</view>
</template>

<script>
	export default {
		name:"qrcode",
		data() {
			return {
				show:false
			};
		},
		methods:{
			close() {
				this.show = false;
			},
		}
	}
</script>

<style lang="scss">

</style>
3.引入、注册、使用组件

在需要使用的页面引入、注册、使用。
引入、注册:

//引入组件
<script>
	import qrcode from '@/components/qrcode/qrcode.vue'
	export default {
	    //注册组件
		components: {
			qrcode
		},
		data() {
			return {
			}
		},
		methods: {
			// 二维码弹出层
			open() {
				this.$refs.qrcode.show = true 
			},
		}
	}
</script>

使用:

<view class="qrcode" @click="open()">
	<image :src="$common.image('/static/images/qrcode.png')" mode="aspectFit" class="qrcodeSmall"></image>
</view>
<template>
	<view class="content">
		<!-- 二维码弹层组件 -->
		<qrcode ref="qrcode"></qrcode>
	</view>
</template>

二、总结

ref的使用:
https://www.cnblogs.com/dianzan/p/12403353.html
弹出层:
https://www.uviewui.com/components/popup.html

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值