elemen ui Table表格中添加图片

一、需求

1.在table表格中添加图片
2.图片展示统一大小,默认展示三张图片,超过3张其余隐藏,点击可查看大图
3.无图时展示暂无图片

如图

二、源码

javascript 复制代码
<template>
  <div class="app-container">


    <el-table :data="listData" border stripe height="600" class="tableBox">
      <el-table-column type="expand">
        <template slot-scope="props">
          <div class="contentBox">
            <div class="titleBox">
              <div class="rectangular"></div>
              <div class="text">人员信息</div>
            </div>
            <el-table :data="props.row.dispatchInfoList" border stripe>
              <el-table-column type="index" width="50" align="center" label="序号">
              </el-table-column>
              <el-table-column label="表头1" align="center" prop="test" show-overflow-tooltip />
              <el-table-column label="表头2" align="center" prop="test" show-overflow-tooltip />

              <el-table-column label="最新现场图片" align="center" prop="images" width="170">
                <template slot-scope="prop">
                  <!-- 拆分图片列表并过滤空值 -->
                  <div v-if="prop.row.images" style="display: flex; align-items: center;">
                    <!-- 只显示前3张图片 -->
                    <el-image v-for="(img, index) in prop.row.images.split(',').filter(i => i).slice(0, 3)" :key="index"
                      style="width: 50px; height: 50px; margin-right: 5px; cursor: pointer" :src="img"
                      :preview-src-list="prop.row.images.split(',').filter(i => i)" fit="cover" lazy>
                      <template #error>
                        <div
                          style="width: 50px; height: 50px; background: #f5f7fa; display: flex; align-items: center; justify-content: center; font-size: 12px; color: #999;">
                          缺
                        </div>
                      </template>
                    </el-image>

                    <!-- 超过3张时显示剩余数量 -->
                    <div v-if="prop.row.images.split(',').filter(i => i).length > 3"
                      style="width: 50px; height: 50px; background: #f5f7fa; display: flex; align-items: center; justify-content: center; font-size: 14px; color: #666;">
                      +{{prop.row.images.split(',').filter(i => i).length - 3}}
                    </div>
                  </div>

                  <!-- 无图片时显示占位 -->
                  <div v-else
                    style="width: 150px; height: 50px; background: #f5f7fa; display: flex; align-items: center; justify-content: center; font-size: 12px; color: #999;">
                    <i class="el-icon-picture-outline" style="margin-right: 5px;"></i>
                    无图片
                  </div>
                </template>
              </el-table-column>


            </el-table>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="表头1" align="center" prop="test" show-overflow-tooltip />
      <el-table-column label="表头2" align="center" prop="test" show-overflow-tooltip />

    </el-table>



  </div>
</template>

<script>
export default {
  name: 'AlertList',
  data() {
    return {
      // 任务表格数据
      listData: [
        {
          "test": "测试",
          "dispatchInfoList": [
            {

              "test": "测试1",
              "images": "https://pic.rmb.bdstatic.com/bjh/01cf57565968e78b239b0eda34e6f3bd5502.jpeg@h_1280,https://sns-webpic-qc.xhscdn.com/202509011558/534f8c33a77056e47b666161ade4b34e/notes_pre_post/1040g3k831kukea78j0205nolaf1g8188joacp88!nd_dft_wlteh_webp_3,https://sns-webpic-qc.xhscdn.com/202509011558/347f4ca62f8cdd7f585e0328b08e9446/notes_pre_post/1040g3k831kukea78j01g5nolaf1g8188fe059lo!nd_dft_wlteh_webp_3,https://sns-webpic-qc.xhscdn.com/202509011558/6e9b3c49daa6bd784def68eaa63bf8cc/notes_pre_post/1040g3k831kukea78j0105nolaf1g8188tbcojdg!nd_dft_wlteh_webp_3,https://sns-webpic-qc.xhscdn.com/202509011558/5d58a6f33329148a1e38f71ca84c91bd/notes_pre_post/1040g3k831kukea78j00g5nolaf1g81880bev4q8!nd_dft_wlteh_webp_3",

            },
            {

              "test": "测试2",
              "images": "",

            },
          ]
        }
      ]
    }
  },
  async mounted() {

  },
  created() {

  },
  methods: {

  }
}
</script>
<style lang="scss" scoped>

//main-container全局样式
.app-container {
  background: #fff;
  height: calc(100%);
  padding: 20px;
}

.tableBox {
  margin-top: 20px;
}

.contentBox {
  width: 100%;
  height: 100%;
  padding: 0px 50px;
  margin-top: 20px;
  display: flex;
  flex-direction: column;

  .titleBox {
    width: 100%;
    height: 22px;
    display: flex;
    align-items: center;
    margin-bottom: 5px;

    .rectangular {
      height: 14px;
      width: 4px;
      background: #eb4b4b;
      border-radius: 8px;
      margin-right: 10px;
    }

    .text {
      font-size: 16px;
      font-weight: 500;
    }
  }
}

.cardBox {
  padding: 20px;
}

::v-deep .el-drawer__header {
  align-items: center;
  color: #72767b;
  display: flex;
  margin-bottom: 32px;
  padding: 20px 20px 0;

  span {
    font-size: 16px
  }
}
</style>
相关推荐
Object~2 分钟前
4.const和iota
开发语言·前端·javascript
小小小小宇4 分钟前
前端监测界面内存泄漏
前端
掘金安东尼4 分钟前
⏰前端周刊第 448 期(2026年1月4日-1月10日)
前端·面试·github
攀登的牵牛花8 分钟前
前端向架构突围系列 - 工程化(一):JavaScript 演进史与最佳实践
前端·javascript
夏天想11 分钟前
为什么使用window.print打印的页面只有第一页。其他页面没有了。并且我希望打印的是一个弹窗的内容,竟然把弹窗的样式边框和打印的按钮都打印进去了
前端·javascript·html
FinClip13 分钟前
凡泰极客FinClip荣获2025中国企业IT大奖!AI+超级APP重塑企业AI服务
前端·架构·openai
小酒星小杜20 分钟前
在AI时代下,技术人应该学会构建自己的反Demo地狱系统
前端·vue.js·ai编程
kirito707740 分钟前
前端项目架构(基于 monorepo)
前端
去哪儿技术沙龙1 小时前
Qunar酒店搜索排序模型的演进
前端·架构·操作系统
重铸码农荣光1 小时前
TypeScript:JavaScript 的“防坑装甲”,写代码不再靠玄学!
前端·react.js·typescript