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

参考效果

当轮播图滑动切换的时候更新自定义下标 ,当图片被点击的时候大图预览

参考代码

商品详情页轮播图交互

javascript 复制代码
<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>
相关推荐
Geek_Vison1 天前
2026 跨端框架横评:FinClip、Taro、uni-app、Remax、mPaaS 五款工具技术+业务双维度测评
小程序·uni-app·taro·mpaas·小程序容器
RuoyiOffice1 天前
从 0 到 1 搭建 RuoyiOffice:30 分钟跑通后端+前端+移动端
前端·spring boot·uni-app·开源·oa·ruoyioffice·hrm
Geek_Vison1 天前
APP集成了50多个小程序后,如何搭建一个小程序管理平台来管理这些小程序~
小程序·uni-app·apache·mpaas·小程序容器
梦曦i2 天前
uni-router v1.1.1发布:守卫超时保护+路由监听
前端·uni-app
梦曦i2 天前
全面解析uni-router v1.2.0功能
前端·uni-app
不如摸鱼去2 天前
Wot UI 2.1.0 发布:ConfigProvider 全局配置能力升级
ui·小程序·uni-app
PedroQue992 天前
uni-router:uni-app路由管理新选择
前端·uni-app
这是个栗子2 天前
微信小程序开发(九)- uni-app微信小程序商城
微信小程序·小程序·uni-app·vue·vuex
中犇科技2 天前
2026商城APP开发公司 TOP5(电商垂直版)
uni-app
扁豆的主人2 天前
Uniapp如何构建和部署
uni-app