uni-app 启动页swiper

这是一个基于Vue.js的滑动引导页组件实现。通过`<swiper>`和`<swiper-item>`组件展示图片,并结合`uni-app`的API进行页面间跳转。在滑动到最后一张时,经过延时后自动跳转到首页。代码中设置了滑动效果、指示点、自动播放等特性,并根据设备窗口尺寸动态调整高度和宽度。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<template>
    <view id="guide">
		 <swiper class="swiper" :style="{height:height+'px'},{width:width+'px'}"
		  indicator-color='#34FF47'
		  indicator-active-color='#ff0000'
		  indicator-dots=true 
		  autoplay=false 
		  interval="3000" 
		  duration="500"
		  easing-function='easeInCubic'
		  @change='EventHandle' 
		  :current="current"
		  >
			<swiper-item  v-for="(item, index) in guidelList" :key="index">
				<image class="banner" :src="item.img_text"  mode="widthFix"></image>
			</swiper-item>                  
		</swiper>		
    </view>
</template>

<script>
	
	export default {
		data(){
			return{
				guidelList:[],
				height:731,
				width:0	,
				current:0,
				isCurrentTabs:'',
				num:''
			}	
		},
		onLoad() {
		  // 从本地缓存中同步获取指定 key 对应的内容,用于判断是否是第一次打开应用
		  this.getBanner();
		     
		},
		methods:{
                        //监听当前的index是否是最后一个,如果是,则进入首页
			EventHandle(e){
				if (typeof(e) == "number") {  
					this.isCurrentTabs = e  
					console.log(this.isCurrentTabs);  
				} else {  
					this.isCurrentTabs = e.detail.current  
					if(this.isCurrentTabs==this.num){
						setTimeout(function() {
							uni.redirectTo({
								url: '/pages/index/index'
							});
						},2000) 
					}
				}  
			},
                         //获取接口返回的图片数据
			getBanner(){
				 let that = this;
				 uni.getSystemInfo({
				     success: function (res) {
						 that.height = res.windowHeight;
						 that.width = res.windowWidth;
				     }
				 });
				
				  this.height = that.height;
				  this.width = that.width;
				let uri = '接口地址';
				this.$api.http.post(uri, {}).then(res => {
					if (res.code == 1) {
						//获取列表
					 	this.guidelList = res.data;
						this.num=this.guidelList.length-1;
						console.log(this.num);
						 setTimeout(function() {
							
						}, 2000* res.data.length) 
					
					} 
				});
			}
		}
	}
	
</script>
  

<style lang="less">
	#guide{
		height:100vh;
		width: 100%;
		.swiper{
				height:100vh;
				width: 100%;
			image{
				height: 100%!important;
			}
		}
	}
	.banner{
		height:100vh;
		width: 100%;
	}
</style>

 

大无语事件通常是指在应用程序启动时,用户等待的时间过长,导致用户体验不佳。为了解决这个问题,可以使用预加载技术或者启动页/引导页等方式来优化用户体验。 对于uni-app应用,可以使用uni-app提供的启动页和引导页来优化用户体验。但是,在使用启动页和引导页时,可能会出现短暂闪屏的问题。这是因为当应用程序启动时,系统需要加载各种资源,而这些资源可能需要一定的时间才能加载完成。在这段时间内,页面可能会出现闪屏。 为了解决这个问题,可以采用以下几种方法: 1. 使用预加载技术:在应用程序启动前,提前加载必要的资源,例如图片、CSS、JS等。这样可以减少页面加载时间,从而避免闪屏问题。 2. 使用 Loading 组件:在页面加载时,显示一个 Loading 组件,提示用户等待。等页面加载完成后,再隐藏 Loading 组件,显示正式内容。 3. 使用透明背景:在启动页和引导页中,使用透明背景,避免出现白屏或黑屏的情况。 以下是一个基于uni-app启动页和引导页示例代码: 启动页: ``` <template> <view class="container"> <image class="logo" src="../static/logo.png"></image> <loading class="loading" type="spinner"></loading> </view> </template> <script> export default { mounted() { // 预加载资源 this.preload() }, methods: { preload() { // 预加载代码 // ... // 预加载完成后,跳转到主页 uni.redirectTo({ url: '/pages/home/home' }) } } } </script> <style> .container { width: 100%; height: 100%; display: flex; flex-direction: column; justify-content: center; align-items: center; background-color: #ffffff; } .logo { width: 100px; height: 100px; } .loading { margin-top: 20px; } </style> ``` 引导页: ``` <template> <swiper class="swiper" :autoplay="true"> <swiper-item> <image class="slide" src="../static/slide1.png"></image> </swiper-item> <swiper-item> <image class="slide" src="../static/slide2.png"></image> </swiper-item> <swiper-item> <image class="slide" src="../static/slide3.png"></image> <button class="button" @click="enterApp">进入应用</button> </swiper-item> </swiper> </template> <script> export default { methods: { enterApp() { // 进入应用 uni.redirectTo({ url: '/pages/home/home' }) } } } </script> <style> .swiper { width: 100%; height: 100%; } .slide { width: 100%; height: 100%; background-size: cover; } .button { position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%); background-color: #ffffff; color: #333333; font-size: 16px; padding: 10px 20px; border-radius: 20px; border: 1px solid #333333; } </style> ``` 这是一个比较简单的示例,具体实现方式可以根据自己的需求来调整。希望对你有帮助!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值