Guide引导页 vue3国际化实现

先看效果
在这里插入图片描述
思路
基于 driver.js 实现

1.npm i driver.js@0.9.8

模板代码
<SvgIcon icon="guide" @click="onClick" id="guide-start"/>
<script setup>
import Driver from 'driver.js'
import 'driver.js/dist/driver.min.css'
import { onMounted } from 'vue'
import { useI18n } from 'vue-i18n'
import steps from './steps'
const i18n = useI18n()

let driver = null
onMounted(() => {
  driver = new Driver({
    // 禁止点击蒙版关闭
    allowClose: false,
    closeBtnText: i18n.t('msg.guide.close'),
    nextBtnText: i18n.t('msg.guide.next'),
    prevBtnText: i18n.t('msg.guide.prev')
  })
})
const onClick = () => {
  driver.defineSteps(steps(i18n))
  driver.start()
}
</script>

2.创建步骤

步骤上面element的值就是对应组件上面的id 要在组件上面写上id就可

const steps = i18n => {
  return [
    {
      element: '#guide-start',
      popover: {
        title: i18n.t('msg.guide.guideTitle'),
        description: i18n.t('msg.guide.guideDesc'),
        position: 'bottom-right'
      }
    },
    {
      element: '#guide-hamburger',
      popover: {
        title: i18n.t('msg.guide.hamburgerTitle'),
        description: i18n.t('msg.guide.hamburgerDesc')
      }
    },
    {
      element: '#guide-breadcrumb',
      popover: {
        title: i18n.t('msg.guide.breadcrumbTitle'),
        description: i18n.t('msg.guide.breadcrumbDesc')
      }
    },
    {
      element: '#guide-search',
      popover: {
        title: i18n.t('msg.guide.searchTitle'),
        description: i18n.t('msg.guide.searchDesc'),
        position: 'bottom-right'
      }
    },
    {
      element: '#guide-full',
      popover: {
        title: i18n.t('msg.guide.fullTitle'),
        description: i18n.t('msg.guide.fullDesc'),
        position: 'bottom-right'
      }
    },
    {
      element: '#guide-theme',
      popover: {
        title: i18n.t('msg.guide.themeTitle'),
        description: i18n.t('msg.guide.themeDesc'),
        position: 'bottom-right'
      }
    },
    {
      element: '#guide-lang',
      popover: {
        title: i18n.t('msg.guide.langTitle'),
        description: i18n.t('msg.guide.langDesc'),
        position: 'bottom-right'
      }
    },
    {
      element: '#guide-tags',
      popover: {
        title: i18n.t('msg.guide.tagTitle'),
        description: i18n.t('msg.guide.tagDesc')
      }
    },
    {
      element: '#guide-sidebar',
      popover: {
        title: i18n.t('msg.guide.sidebarTitle'),
        description: i18n.t('msg.guide.sidebarDesc'),
        position: 'right-center'
      }
    }
  ]
}
export default steps

要在Uniapp中实现App引导轮播,可以按照以下步骤进行开发: 1. 创建一个面作为App引导,可以在该面中添加多个图片作为轮播的引导。 2. 在该面中引入uni-ui组件库的swiper组件,用于实现轮播效果。 3. 在面的data中定义一个数组,用于存储所有的引导图片链接。 4. 在面的mounted生命周期函数中,将所有引导图片链接添加到data中定义的数组中。 5. 在swiper组件中使用v-for指令遍历data中的引导图片链接,生成多个swiper-item组件,并设置每个swiper-item组件的背景图片为对应的引导图片链接。 6. 在swiper组件中设置自动轮播和循环轮播等参数,以及添加分器和左右箭头等控制器。 7. 最后,将该App引导作为App的启动,在App.vue中配置启动为该面即可。 示例代码如下: ```html <template> <view> <swiper :autoplay="true" :circular="true" :indicator-dots="true" :indicator-color="'#999'" :indicator-active-color="'#333'" :previous-margin="'50rpx'" :next-margin="'50rpx'"> <swiper-item v-for="(imgUrl, index) in imgList" :key="index"> <view class="swiper-item" :style="{backgroundImage: 'url(' + imgUrl + ')'}"></view> </swiper-item> </swiper> </view> </template> <script> import uniSwiperDot from '@/components/uni-swiper-dot/uni-swiper-dot.vue'; export default { components: { uniSwiperDot }, data() { return { imgList: [] // 存储所有的引导图片链接 }; }, mounted() { this.imgList = [ 'https://xxx.com/guide_1.jpg', 'https://xxx.com/guide_2.jpg', 'https://xxx.com/guide_3.jpg' ]; // 添加所有的引导图片链接 } }; </script> <style lang="scss" scoped> .swiper-item { width: 100%; height: 100vh; background-size: cover; background-position: center; } </style> ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值