小程序引导页开发

需求描述

  1. 引导页以轮播图的形式展示,滑动图片,点击【立即体验】使用程序
  2. 只在初次使用程序时才展示,之后不再展示

实现步骤

在pages.json添加一个新页面guide.vue

{
	"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
    {
      "path": "pages/guide/guide",
      "style": {
        "navigationStyle": "custom"
      }
    },
		{
			"path": "pages/home/home",

在App.vue的onLaunch中判断进入哪个页面

缓存isFirst,代表是否看过引导页

  • isFirst=true,表示已经看过引导页,进入首页-home页面
  • isFirst=false,表示已经没过引导页,进入引导页-guide页面
onLaunch: function() {	
	let isFirst=this.$common.getFirstuse();
    if(isFirst){
        uni.switchTab({
          url: '/pages/home/home'
        });
    }else{
        uni.hideTabBar();
        uni.redirectTo({
          url: '/pages/guide/guide'
        });
    }
},

在guide.vue的点击【立即体验】时,设置缓存isFirst为true

<template>
  <swiper indicator-dots="true">
    <swiper-item v-for="(item,index) in imgs" :key="index">
      <image class="swiper-image" :src="item"></image>
      <button class="button-img" @click="start" v-if="index == (imgs.length - 1)">立即体验</button>
    </swiper-item>
  </swiper>
</template>

<script>
  export default {
    data() {
      return {
        imgs: [
          "https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=3488277290,2629434387&fm=173&app=25&f=JPEG?w=640&h=480&s=BDA4CB11840AD34D181ABDC10300F0BF",
          "https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=2161074131,1615497748&fm=173&app=25&f=JPEG?w=640&h=480&s=ABCA27D3064052EC0EB1EF5403005072",
          "https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=2724095192,3893371048&fm=173&app=25&f=JPEG?w=640&h=802&s=AD10A454EC57704D152A7B980300C09E",
        ],
      }
    },
    methods: {
      start() {
        this.$common.setFirstuse(true);
        uni.switchTab({
          url: '/pages/home/home'
        })
      },
    }
  }
</script>

<style scoped>
  swiper {
    position: absolute;
    height: 100%;
    width: 100%;
  }

  .swiper-image {
    height: 100%;
    width: 100%;
    opacity: 0.9;
  }

  .button-img {
    height: 40px;
    width: 120px;
    position: absolute;
    opacity: 0.6;
    left: 50%; 
    bottom: 5%; 
    transform: translate(-50%, -50%);
  }

</style>

微信、支付宝小程序和微信公众号均可使用

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

佛佛ง

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值