vue表格显示图片,采用element ui实现

项目场景:

vue表格显示图片,采用element ui实现


  <template>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="date" label="Date" width="180" />
      <el-table-column prop="name" label="Name" width="180" />
      <el-table-column prop="address" label="Address" />
      <el-table-column prop="img" label="图片" width="100">
        <template v-slot:default="scope">
          <el-image :src="scope.row.img"/>
        </template>


      </el-table-column>
    </el-table>
  </template>


<script lang="ts" >
const tableData = [
  {
    date: '2016-05-03',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
    img: '/image/cover1.png'
  },
  {
    date: '2016-05-02',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
    img: '/image/cover2.png'
  },
  {
    date: '2016-05-04',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
    img: '/image/cover2.png'
  },
  {
    date: '2016-05-01',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
    img: '/image/cover1.png'
  },
]
export default {
  name: "showpicture",

  data(){
    return{
      tableData
    }
  }
}
</script>

<style scoped>

</style>

流程描述:

首先定义一个数组tableData,然后return这个数组,采用element的表格模板,需要注意的是el-table-column标签包裹着el-image图片显示标签,但是由于作用域插槽只允许在template模板使用,所以el-image图片显示标签外加一层template模板标签,在vue3中作用域插槽为
v-slot:default=“scope”,scope是随意起的名字,该作用域插槽的含义可以解释为scope内含有el-table-column标签的全部属性采用格式scope.row.img调用。

<el-table-column prop="img" label="图片" width="100">
        <template v-slot:default="scope">
          <el-image :src="scope.row.img"/>
        </template>


      </el-table-column>

  • 12
    点赞
  • 43
    收藏
    觉得还不错? 一键收藏
  • 10
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值