elementPlus在table表格中实现图片移入放大效果

方法参照官网的写法,但是官网的写法是使用的url地址,而我的需求是使用传入的地址。

先分析官网写法(我截取需要的部分)

<template>
  <div style="display: flex; align-items: center">
    <el-popover
      :width="300"
      popper-style="box-shadow: rgb(14 18 22 / 35%) 0px 10px 38px -10px, rgb(14 18 22 / 20%) 0px 10px 20px -15px; padding: 20px;"
    >
      <template #reference>
        <el-avatar src="https://avatars.githubusercontent.com/u/72015883?v=4" />
      </template>
      <template #default>
        <div
          class="demo-rich-conent"
          style="display: flex; gap: 16px; flex-direction: column"
        >
          <el-avatar
            :size="60"
            src="https://avatars.githubusercontent.com/u/72015883?v=4"
            style="margin-bottom: 8px"
          />
          <div>
            <p
              class="demo-rich-content__name"
              style="margin: 0; font-weight: 500"
            >
              Element Plus
            </p>
            <p
              class="demo-rich-content__mention"
              style="margin: 0; font-size: 14px; color: var(--el-color-info)"
            >
              @element-plus
            </p>
          </div>

          <p class="demo-rich-content__desc" style="margin: 0">
            Element Plus, a Vue 3 based component library for developers,
            designers and product managers
          </p>
        </div>
      </template>
    </el-popover>
  </div>
</template>

上面的 #reference 表示正常情况下显示的内容 #default 为当鼠标移入后显示的内容,因为这里是用的网络图片,而我需要的是table中传入进来的地址
所以要想实现这个功能就要给这个tanble中的值传入数据。所以在这个代码之上,我又嵌套了一层template

<el-table-column label="图片" width="150">
        <!-- scope.row.menuPicture -->
        <template #default="scope">
          <el-popover :width="300" placement="right">
            <template #reference>
              <el-image :src="scope.row.menuPicture" width="50px" />
            </template>
            <template #default>
              <div
                class="demo-rich-conent"
                style="display: flex; gap: 16px; flex-direction: column"
              >
                <el-image
                  :size="60"
                  :src="scope.row.menuPicture"
                  style="margin-bottom: 8px"
                />
              </div>
            </template>
          </el-popover>
        </template>
      </el-table-column>

这里最外层的template添加了table表传递过来的scope 然后再在下面需要的地方设置src值,实现自己需要的功能
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值