vue3中在elementplus多行表格中渲染多图数组中首图的显示问题,无法正常显示图片,作用域插槽写法问题

背景

 在vue3中使用elementplus的el-table组件的时候,此时我在vue生命周期中挂载时获取了到服务器了数据,这个数据是一个多个对象的数组,各个对象又包括了图片数组,此时我想在表格上的每一行渲染图片的首图,也就是下标为0的图片,但是出现图片无法正常显示

vue中写法部分代码,tableData是已知的数组:

<template>
  <el-table :data="tableData" style="width: 100%">
    <el-table-column fixed prop="pm" label="品名" width="150" />
    <el-table-column prop="bt" label="标题" width="120" />
    <el-table-column prop="jg" label="价格" width="120" />
    <el-table-column prop="td" label="特点" width="120" />
    <el-table-column prop="jhl" label="净含量" width="120" />
    <el-table-column prop="bz" label="包装" width="120" />
    <el-table-column prop="cd" label="产地" width="120" />
    <el-table-column prop="bzrq" label="保质日期" width="120" />
    <el-table-column prop="syff" label="食用方法" width="120" />
    <el-table-column prop="plb" label="配料表" width="300" />
    <el-table-column prop="zmwz" label="致敏物质" width="120" />
    <el-table-column prop="zctj" label="贮存条件" width="120" />
    <el-table-column prop="wxts" label="温馨提示" width="120" />
    <el-table-column prop="tp" fixed="right" label="首图" width="120">
      <template slot-scope="scope">
        <el-image v-if="scope && scope.row" style="width: 100px; height: 100px" :src="scope.row.tp[0]"  />
        <span v-else>无图片</span>
      </template>
    </el-table-column>
    <el-table-column fixed="right" label="操作" width="120">
      <el-button link type="primary" size="small">修改</el-button>
      <el-button link type="primary" size="small" @click="handleClick">删除</el-button>
    </el-table-column>
  </el-table>
</template>

出现的问题

 首图无法显示,出现这个scope问题。Property "scope" was accessed during render but is not defined on instance.

解决方案

使用v-slot替代slot-scope:在Vue 2中,你可以使用slot-scope来获取作用域插槽的数据。但在Vue 3中,slot-scope已被废弃,取而代之的是使用v-slot指令。你可以尝试将slot-scope="scope"替换为v-slot="scope"。

部分改正后代码:

<template v-slot="scope">
  <el-image v-if="scope && scope.row" style="width: 100px; height: 100px" :src="scope.row.tp[0]"  />
  <span v-else>无图片</span>
</template>

 然后就好啦~

如果这篇对你有帮助的话~点个赞赞再走吧~~~~~~~ 

  • 12
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

浩冉学编程

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值