需求:h5和小程序预览图片需要有当前第几张标识

1.小程序直接使用api:uni.previewImage

2.h5使用轮播图写一个组件

javascript 复制代码
<template>
    <view class="custom-image-preview" v-if="visible">
      <view class="overlay"></view>
      <swiper class="swiper" :current="currentIndex" @change="onSwiperChange">
        <swiper-item v-for="(image, index) in images" :key="index" @click="closePreview">
          <image style="width: 100%;height: 100%;" :src="image" mode="aspectFit" class="preview-image" :show-menu-by-longpress="true"></image>
        </swiper-item>
      </swiper>
      <view class="index-indicator">
        {{ currentIndex + 1 }} / {{ images.length }}
      </view>
    </view>
  </template>
  
  <script>
  export default {
    props: {
      images: {
        type: Array,
        required: true,
      },
      current: {
        type: Number,
        default: 0,
      },
    },
    data() {
      return {
        visible: false,
        currentIndex: 0,
      };
    },
    methods: {
      openPreview() {
        this.currentIndex = this.current;
        this.visible = true;
      },
      closePreview() {
        this.visible = false;
        this.$emit('close');
      },
      onSwiperChange(e) {
        this.currentIndex = e.detail.current;
      },
    },
    mounted() {
      this.openPreview();
    },
  };
  </script>
  
  <style scoped>
  .custom-image-preview {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9999;
  }
  
  .overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
  }
  
  .swiper {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
  }
  
  .preview-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
  }
  
  .index-indicator {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    color: #fff;
    font-size: 24px;
    background: rgba(0, 0, 0, 0.5);
    padding: 8px 16px;
    border-radius: 16px;
  }
  </style>
相关推荐
故七月几秒前
GEO 信源评估体系:如何判断一条网页信源能否被大模型采信
前端·网络·人工智能
liangshanbo12152 分钟前
Webpack 常见 Plugin 面试题
前端·webpack·node.js
xxwl5854 分钟前
vue3的入门学习
前端·vue.js·学习
用户847172102845 分钟前
.shot 文件格式规范
前端·后端
web打印社区7 分钟前
政务办事大厅:叫号小票、办理回执网页怎么静默出纸
前端·javascript·vue.js·pdf·html·政务
C++ 老炮儿的技术栈29 分钟前
有符号变量与无符号变量的区别
服务器·开发语言·前端·数据结构·c++·算法·c
aixingpan39 分钟前
aixingpan.cn API开发文档:api_docs_bichart_natalvssecondary2接口指南
前端·php
liangshanbo12151 小时前
Webpack Tree Shaking 面试题整理
前端·webpack·node.js
Ai-_Man1 小时前
您您这可以把Google AI Studio的多个会话比如说。左侧的多个会话一次性导出吗?不是单条会话里面的多次会对话。AI导出鸭
javascript·人工智能·ai·小程序·电脑
去伪存真1 小时前
从乱码到高精度检索:探矿业务中 TXT、Word、PDF 与网页的 RAG 清洗之道
前端·agent