vben5 ImageUpload 模块多图预览功能

upload 中自定义回调预览回调逻辑

ini 复制代码
<template>
  <div>
    <Upload
      v-bind="$attrs"
      v-model:file-list="fileList"
      :accept="getStringAccept"
      :before-upload="beforeUpload"
      :custom-request="customRequest"
      :disabled="disabled"
      :list-type="listType"
      :max-count="maxNumber"
      :multiple="multiple"
      :progress="{ showInfo: true }"

      @preview="handlePreview"
      @remove="handleRemove"
    >

    <!--修改为多图预览-->
    <div style="display: none" >
      <ImagePreviewGroup :preview="{ visible,current:current, onVisibleChange: vis => (visible = vis) }">
        <Image v-for="item in fileList"
          :src="item.url"
        />
      </ImagePreviewGroup>
    </div>
  </div>
</template>

handlePreview 回调

计算current 图片索引和开启预览

ini 复制代码
/** 处理图片预览 */
async function handlePreview(file: UploadFile) {

  if (!file.url && !file.preview) {
    file.preview = await getBase64<string>(file.originFileObj!);
  }
  current.value= fileList.value.findIndex((item) => item.url === file.url);

  previewImage.value = file.url || file.preview || '';
  previewOpen.value = true;
  visible.value = true;
  previewTitle.value =
    file.name ||
    previewImage.value.slice(
      Math.max(0, previewImage.value.lastIndexOf("/") + 1)
    );
}
相关推荐
滑雪的企鹅.1 小时前
HTML头部元信息避坑指南大纲
前端·html
一拳不是超人1 小时前
老婆天天吵吵要买塔罗牌,我直接用 AI 2 小时写了个在线塔罗牌
前端·ai编程
excel3 小时前
如何解决 Nuxt DevTools 中关于 unstorage 包的报错
前端
Rust研习社3 小时前
使用 Axum 构建高性能异步 Web 服务
开发语言·前端·网络·后端·http·rust
C澒3 小时前
AI 生码 - API2Code:接口智能匹配与 API 自动化生码全链路设计
前端·低代码·ai编程
浔川python社3 小时前
HTML头部元信息避坑指南技术文章大纲
前端·html
IT_陈寒4 小时前
SpringBoot配置加载顺序把我坑惨了
前端·人工智能·后端
kyriewen4 小时前
Next.js部署:从本地跑得欢,到线上飞得稳
前端·react.js·next.js
Moment4 小时前
面试官:给 llm 传递上下文,有哪几个身份 role ❓❓❓
前端·后端·面试
跨境数据猎手4 小时前
跨境独立站系统技术拆解(附带源码)
服务器·前端·php