vue3之基于el-image实现图片预览

作者 : admin 本文共530个字,预计阅读时间需要2分钟 发布时间: 2024-06-8 共2人阅读

实现的功能:

  1. 图片可放大预览,支持放大、缩小、向左向右旋转查看
  2. 可点击任意一张图后进行左右切换查看大图

主要使用的方法:spliceconcat

主要代码
// template中
<div>
   <el-image
      v-for="(item, index) in imgsData"
      :src="item"
      fit="fit"
      :preview-src-list="getPrivewImages(index)"
   />         
</div>

// method中
const getPrivewImages = (index) => { // index当前点击图片的下标
    let tempImgList = [...imgsData.value];
    if (index == 0) return tempImgList;
    // 删除从 index 开始到数组末尾的元素,并将这些元素作为新数组返回
    let start = tempImgList.splice(index);
    // 删除从索引 0 开始到索引 index(不包括 index)的所有元素,并将这些被删除的元素作为新数组返回
    let remain = tempImgList.splice(0, index);
     // 最终返回的数组将是这两部分的组合,且顺序相反
    return start.concat(remain);
}
本站无任何商业行为
个人在线分享 » vue3之基于el-image实现图片预览
E-->