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

在这里插入图片描述

组件封装

src\components\SUI_Swiper2.vue

<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

<SUI_Swiper2 :config="swiperConfig" />
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,
  }
}

相关推荐

  1. uniapp实现图片放大,长按下载图片

    2023-12-09 08:18:01       39 阅读
  2. uniapp图片功能?

    2023-12-09 08:18:01       62 阅读
  3. Uniapp 图片放大

    2023-12-09 08:18:01       44 阅读
  4. 富文本内容图片实现

    2023-12-09 08:18:01       61 阅读
  5. uni-app图片

    2023-12-09 08:18:01       60 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-09 08:18:01       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-09 08:18:01       106 阅读
  3. 在Django里面运行非项目文件

    2023-12-09 08:18:01       87 阅读
  4. Python语言-面向对象

    2023-12-09 08:18:01       96 阅读

热门阅读

  1. 2023-12-08 工作心得

    2023-12-09 08:18:01       50 阅读
  2. Qt12.8

    Qt12.8

    2023-12-09 08:18:01      55 阅读
  3. MongoDB数据建模与文档设计

    2023-12-09 08:18:01       53 阅读
  4. uniapp封装websocket文件(app、h5兼容)

    2023-12-09 08:18:01       63 阅读
  5. git 命令

    2023-12-09 08:18:01       46 阅读
  6. petalinux 2019.1 在ubuntu 16.04 下的安装

    2023-12-09 08:18:01       50 阅读