(Table)解决:Element-ui 中<template slot-scope=“scope“> 的用法问题以及剖析 Table 的相关属性

1、遇到要在 Element-ui 的 Table 中添加图片和序号的问题:

A、想要在Table里面添加的图片或属性情况为:
在这里插入图片描述
B、但如何添加就是一个问题:
经过查询发现:通过 slot-scope="scope" 属性操作是可以在 table 栏中添加相关属性值的(相关文档也有叙述);

在这里插入图片描述
// 地址:https://element.eleme.cn/#/zh-CN/component/table
// 此时在日期栏下添加了一个图标date值
// 即:通过 slot-scope="scope" 来添加相关属性值是可以的;

2、解决方案:用 slot-scope="scope"属性

A、关于 Element-ui'el-table' 的理解:

其一、属性 :data="tableData" 表示是:动态绑定
el-table 中,:data="tableData" 是动态绑定的对象数组,在 Table 中每一个 cell (小格子) 里面显示的数据都是从动态绑定的对象数组中拿到的数据;

在这里插入图片描述

其二、el-table-column 来决定 el-table 的列数:
<template></template> 里面的 el-table-column 个数来决定 el-table 的列个数,且用 lable 属性来决定列名;
在这里插入图片描述

其三、:data="tableData" 中的对象个数决定 el-table 的行数:

tableData 对象数组里面的 {对象}个数来决定 el-table 的行个数,且用 el-table-column 中的 prop 属性来将该列的数据与tableData数组所有对象中的相关属性绑定;
可以理解为:tableData[$index].adress 来拿到数据;
在这里插入图片描述

// 例如: prop="address" 语句就表示:将该 prop="address" 列的数据与tableData数组所有对象中的address属性绑定;

// prop="address" 所在列:
在这里插入图片描述
// 绑定的tableData数组所有对象中的address属性;
在这里插入图片描述
B、关于slot-scope="scope"属性的理解:

其一、slot-scope="scope"本质上就是一个插槽,简单说就是先在 el-table 中占一个位置,然后再等待操作往里面填值即可;

在这里插入图片描述
其二、在scope.row.address语句中rowscope 的内置属性,应该还会有column, $index 等内置属性;

我理解为:给 label="地址" 列中的每个 row 中添加 tableData 数组所有对象中的 address 属性;

其三、此时的所占位置的 scope 并不是代表着 table,可以将scope.row理解为一个整体,从而来存放 tableData 所有数组对象中的 address 属性值;

3、通过 slot-scope="scope"实现插入图片的过程:

A、通过引入 slot-scope="scope" 属性的代码:

// template 中的代码展示:
<template>
  <div class="container">
    <el-table
      :data="tableData"
      :height="tabHeight"
      :width="tabWidth"
      class="container-table"
      style="width: 100%"
    >
      <el-table-column prop="date" label="日期" width="180"> </el-table-column>
      <el-table-column prop="name" label="姓名" width="180"> </el-table-column>
      <el-table-column prop="address" label="地址"  width="350"> </el-table-column>
      <el-table-column prop="process" label="">
        <template slot-scope="scope">
          <div
           class="table_right"
           v-for="(iterm, indx) in scope.row.process" 
           :key="indx" 
           style="float: left; color: black"
           >
           <div class="span_bg">
             <span class="table-circle">{{ iterm.order }}</span>
             <span class="t_value"> {{ iterm.name }}</span>
           </div>
           <span class="el-icon-right"></span>
          </div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

在这里插入图片描述

B、做出来的页面展示(插入的图片及文字):
在这里插入图片描述

4、小结:

其一、哪里有不对或不合适的地方,还请大佬们多多指点和交流!
其二、有兴趣的话,可以多多关注这个专栏(Vue(Vue2+Vue3)面试必备专栏):https://blog.csdn.net/weixin_43405300/category_11525646.html?spm=1001.2014.3001.5482

  • 63
    点赞
  • 147
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

狮子座的男孩

如果可以,请我喝杯咖啡吧!

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

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

打赏作者

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

抵扣说明:

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

余额充值