uni-app中轮播图实现大图预览

参考效果

当轮播图滑动切换的时候更新自定义下标,当图片被点击的时候大图预览
在这里插入图片描述

参考代码

商品详情页轮播图交互

<script setup lang="ts">
// 轮播图变化时
const currentIndex = ref(0)
const onChange: UniHelper.SwiperOnChange = (ev) => {
   
  currentIndex.value = ev.detail.current
}

// 点击图片时
const onTapImage = (url: string) => {
   
  // 大图预览方法
  uni.previewImage({
   
    current: url, //图片路径
    urls: goods.value!.mainPictures, //预览图片列表
  })
}
</script>

<template>
  <!-- 商品主图 -->
  <view class="preview">
    <swiper @change="onChange" circular>
      <swiper-item v-for="item in goods?.mainPictures" :key="item">
        <image @tap="onTapImage(item)" mode="aspectFill" :src="item" />
      </swiper-item>
    </swiper>
    <view class="indicator">
      <text class="current">{
   {
    currentIndex + 1 }}</text>
      <text class="split">/</text>
      <text class="total">{
   {
    goods?.mainPictures.length }}</text>
    </view>
  </view>
</template>

相关推荐

  1. uniapp实现两边小

    2024-01-10 00:02:03       12 阅读
  2. jQuery实现3D

    2024-01-10 00:02:03       42 阅读
  3. jQuery实现代码

    2024-01-10 00:02:03       44 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-01-10 00:02:03       19 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-01-10 00:02:03       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-01-10 00:02:03       20 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-01-10 00:02:03       20 阅读

热门阅读

  1. Vue的Computed、Methods和Watch

    2024-01-10 00:02:03       48 阅读
  2. 快速排序和冒泡排序

    2024-01-10 00:02:03       39 阅读
  3. linux下数据库定时备份

    2024-01-10 00:02:03       36 阅读
  4. MySQL数据类型

    2024-01-10 00:02:03       45 阅读
  5. 泛型编程-常用模板

    2024-01-10 00:02:03       26 阅读
  6. 怎么形象化理解线程

    2024-01-10 00:02:03       31 阅读
  7. alist重置密码

    2024-01-10 00:02:03       47 阅读
  8. PCL 点云八叉树体素搜索

    2024-01-10 00:02:03       37 阅读
  9. 服务器常见问题以及处理方案

    2024-01-10 00:02:03       32 阅读