uniapp实战 —— 轮播图【数字下标】(含组件封装,点击图片放大全屏预览)

组件封装

src\components\SUI_Swiper2.vue

html 复制代码
<script setup lang="ts">
import { ref } from 'vue'
const props = defineProps({
  config: Object,
})

const activeIndex = ref(0)
const change: UniHelper.SwiperOnChange = (e) => {
  activeIndex.value = e.detail.current
}

// 点击图片时
const onTapImage = (url: string) => {
  // 大图预览
  uni.previewImage({
    current: url,
    urls: props.config?.itemList,
  })
}
</script>

<template>
  <view class="preview">
    <swiper
      @change="change"
      :circular="props.config?.circular || true"
      :autoplay="props.config?.autoplay || false"
      :interval="props.config?.interval || 3000"
    >
      <swiper-item v-for="(item, index) in props.config?.itemList" :key="index">
        <image @tap="onTapImage(item)" mode="aspectFill" :src="item" />
      </swiper-item>
    </swiper>
    <view class="indicator">
      <text class="current">{{ activeIndex + 1 }}</text>
      <text class="split">/</text>
      <text class="total">{{ props.config?.itemList.length }}</text>
    </view>
  </view>
</template>

<style lang="scss">
.preview {
  height: 750rpx;
  position: relative;
  .image {
    width: 750rpx;
    height: 750rpx;
  }
  .indicator {
    height: 40rpx;
    padding: 0 24rpx;
    line-height: 40rpx;
    border-radius: 30rpx;
    color: #fff;
    font-family: Arial, Helvetica, sans-serif;
    background-color: rgba(0, 0, 0, 0.3);
    position: absolute;
    bottom: 30rpx;
    right: 30rpx;
    .current {
      font-size: 26rpx;
    }
    .split {
      font-size: 24rpx;
      margin: 0 1rpx 0 2rpx;
    }
    .total {
      font-size: 24rpx;
    }
  }
}
</style>

页面使用

src\pages\goods\goods.vue

html 复制代码
<SUI_Swiper2 :config="swiperConfig" />
js 复制代码
let swiperConfig = ref({ itemList: [] })

// 获取商品详情信息
const goods = ref<GoodsResult>()
const getGoodsByIdData = async () => {
  const res = await getGoodsByIdAPI(query.id)
  goods.value = res.result
  swiperConfig.value = {
    itemList: goods?.value.mainPictures,
  }
}
相关推荐
昔人'36 分钟前
`list-style-type: decimal-leading-zero;`在有序列表`<ol></ol>` 中将零添加到一位数前面
前端·javascript·html
岁月宁静6 小时前
深度定制:在 Vue 3.5 应用中集成流式 AI 写作助手的实践
前端·vue.js·人工智能
2501_915909066 小时前
“绑定 HTTPS” 的工程全流程 从证书配置到真机验证与故障排查
网络协议·http·ios·小程序·https·uni-app·iphone
saadiya~7 小时前
ECharts 实时数据平滑更新实践(含 WebSocket 模拟)
前端·javascript·echarts
百锦再7 小时前
Vue Scoped样式混淆问题详解与解决方案
java·前端·javascript·数据库·vue.js·学习·.net
2501_915918417 小时前
iOS 混淆实战 多工具组合完成 IPA 混淆、加固与工程化落地(iOS混淆|IPA加固|无源码混淆|Ipa Guard|Swift Shield)
android·ios·小程序·https·uni-app·iphone·webview
Sheldon一蓑烟雨任平生8 小时前
Vue3 表单输入绑定
vue.js·vue3·v-model·vue3 表单输入绑定·表单输入绑定·input和change区别·vue3 双向数据绑定
瓜瓜怪兽亚9 小时前
前端基础知识---Ajax
前端·javascript·ajax
AI智能研究院9 小时前
(四)从零学 React Props:数据传递 + 实战案例 + 避坑指南
前端·javascript·react.js
qq7798233409 小时前
React组件完全指南
前端·javascript·react.js