uni-popup 小程序首页弹出层

景: 要求在首页加载的时候弹出弹框显示一张图片,弹出五秒后自动关闭,也可以点击
叉号手动关闭;如图:
在这里插入图片描述
代码:

<template>
  <u-popup
	class="auth-popup"
	mode="center"
	width="600rpx"
	height="770rpx"
	:closeable="true"
	close-icon-color="#010101"
	:mask-close-able="false"
	close-icon-size="42"
	border-radius="5">
		   <view class="back_box">
				<image
					class="back_img"
					:src="popUpUrl"
					:key="index"
				></image>
			</view>
  </u-popup>
</template>
<script>
	import http from '@/api/http.js';
	import {
		getImsgPushlogmsg
	} from '@/api/interfaceHDB.js';
	
	export default {
		data() {
			return {
				isShowPoupon: false, //是否隐藏对话框
				popUpUrl: "", //首页弹窗图片
			}
		},
		mounted() {
			this.getLogdatainfo();
		},
	    methods: {
			// 获取弹窗内容
			getLogdatainfo() {
				http.get(getImsgPushlogmsg).then(res => {
				    if (res.list[0]) {
						this.popUpUrl = res.list[0].pushmsgJpushType; //图片地址
						this.isShowPoupon = true;
						
						//设置五秒后弹窗自动关闭
						let time = setTimeout(item => {
							this.isShowPoupon = false;
							clearTimeout(time)
						}, 5000)
					} else {
						console.log('没有弹窗数据')
					}
				})
			},
		}
</script>
<style lang="less" scoped>
	.back_box {
		position: relative;
		width: 100%;
		height: 100%;
		
		.back_img {
			width: 100%;
			height: 100%;
		}
	}
</style>

接口数据:
在这里插入图片描述

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你可以使用 `uni-popup` 组件来实现弹出的效果。`uni-popup` 是 uni-app 框架的一个原生弹出组件,可以在页面中创建一个弹出,并控制其显示和隐藏。 首先,确保你已经在你的 uni-app 项目中安装了 `uni-popup` 组件。可以通过以下命令安装: ``` npm install @dcloudio/uni-popup ``` 接下来,在需要使用弹出的页面中,引入 `uni-popup` 组件: ```vue <template> <view> <uni-popup :show="showPopup" @close="closePopup"> <!-- 弹出的内容 --> </uni-popup> <!-- 其他页面内容 --> </view> </template> <script> import uniPopup from '@dcloudio/uni-popup' export default { components: { uniPopup }, data() { return { showPopup: false } }, methods: { openPopup() { this.showPopup = true }, closePopup() { this.showPopup = false } } } </script> ``` 在上述示例中,我们创建了一个 `showPopup` 的 data 属性来控制弹出的显示和隐藏。当点击打开弹出按钮时,调用 `openPopup` 方法将 `showPopup` 设置为 `true`,弹出将显示出来。当点击弹出上的关闭按钮时,会触发 `closePopup` 方法将 `showPopup` 设置为 `false`,弹出将隐藏。 你可以根据需要自定义弹出的内容,例如在 `<uni-popup>` 标签内添加你想要展示的内容。 这样就可以通过 `uni-popup` 组件来实现弹出的效果了。记得根据实际情况调整代码,并在合适的时机调用 `openPopup` 方法来显示弹出
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值