Element Plus 表格table中,el-image实现图片预览无层级显示问题

在日常开发中,使用el-table时候需要对缩略图进行点击预览效果,但是一般会有层级显示问题,如下图

解决以上问题,直接copy下侧代码即可:

javascript 复制代码
<el-table-column prop="imageUrl" label="图片">
            <template #default="scope">
              <template v-if="scope.row.imageUrl">
                <el-image
                  style="width: 50px; height: 50px"
                  :src="scope.row.imageUrl"
                  @click="handlePreview(scope.row.imageUrl)"
                  :preview-src-list="[]"
                />
              </template>
              
				//异常情况处理,无图片展示
              <div
                v-else
                style="
                  width: 50px;
                  height: 50px;
                  line-height: 50px;
                  text-align: center;
                  color: #999;
                  background-color: #f5f7fa;
                  font-size: 12px;
                "
              >
                暂无图片
              </div>

			// 预览层级直接在body上
              <teleport to="body">
                <el-image-viewer
                  v-if="previewVisible"
                  @close="closePreview"
                  :url-list="previewImages"
                  :z-index="3000"
                />
              </teleport>
            </template>
          </el-table-column>
javascript 复制代码
const previewVisible = ref(false)
const previewImages = ref([])

const handlePreview = images => {
  previewImages.value = [images]// el-image组件预览时数据要求是数组
  previewVisible.value = true
  nextTick(() => {
    const viewer = document.querySelector('.el-image-viewer')
    if (viewer) viewer.style.zIndex = 3000
  })
}

实现如下所示:

相关推荐
热爱运维的小七7 小时前
从传统架构到云原生,如何应对数据增长挑战?
数据库·it运维·devops·1024程序员节
huangyuchi.7 小时前
【Linux网络】套接字Socket编程预备
linux·运维·服务器·端口号·linux网络·套接字·1024程序员节
稍带温度的风7 小时前
node 后端服务 PM2 相关命令
node.js·pm2·1024程序员节
Brandon汐7 小时前
MySQL的安装与卸载
1024程序员节
胡耀超7 小时前
5、服务器互连技术(小白入门版)
服务器·网络·ai·网络拓扑·gpu·pcie·1024程序员节
C灿灿数模7 小时前
2025MathorCup大数据竞赛B题思路模型详细分析:物流理赔风险识别及服务升级问题
1024程序员节
DKunYu7 小时前
2.2softmax回归
pytorch·python·深度学习·1024程序员节
努力进修7 小时前
用 Excalidraw+cpolar 做会议协作,像素级还原实体白板体验
cpolar·1024程序员节·excalidraw
victory04317 小时前
whisper 模型处理音频办法与启示
1024程序员节