首页 > 其他分享 >Vue前端多图展示

Vue前端多图展示

时间:2024-06-24 11:44:32浏览次数:22  
标签:index arr Vue return 前端 多图 length const imageList

<el-table-column label="图片" align="center" width="180px" :show-overflow-tooltip="false">
        <template #default="scope">
          <el-image fit="fill" style="width:40px;height: 40px;margin-left: 6px;"
            v-for="(item, index) in getShowImageList(scope.row.imageList)" :key="index" :preview-teleported="true"
            :src="item" :preview-src-list="getImgList(scope.row.imageList, index)" />
        </template>
      </el-table-column>
// 预览图片列表生成,主要用于生成一个点击图片为第一张的列表
const getImgList = (imageList, index) => {
  let arr = [] as any[]
  if (imageList.length == 1) {
    arr.push(imageList[0])
  } else if (imageList.length == 0) {
    return arr;
  } else {
    for (let i = 0; i < imageList.length; i++) {
      arr.push(imageList[i + index])
      if (i + index >= imageList.length - 1) {
        index = 0 - (i + 1);
      }
    }
  }
  return arr;
}

const getShowImageList = (imageList) => {
  if (imageList == null) {
    return []
  }
  // 判断ImageList长度
  if (imageList.length <= 3) {
    return imageList
  } else {
    return imageList.slice(0, 3)
  }
}

标签:index,arr,Vue,return,前端,多图,length,const,imageList
From: https://www.cnblogs.com/eaglex3/p/18264676

相关文章