vue---table中姓名列显示头像和姓名

1、需求描述:

table中员工姓名列只显示姓名

希望table中员工姓名列前加上一个图片,图片内容为姓名后两个字,则姓名列显示头像和姓名

       

2、思路

  • 利用【<template slot-scope="scope"> ...</template>】,将显示数据拆分为两块显示,即下面代码中两个【 <span>...</span>】
  • 这里姓名假设为只有两个字和三个字的姓名,如果姓名第三位有字,则显示后两位;如果为两个字的姓名,则全部显示,使用【  <span v-if="scope.row.name[2]">... </span>】做判断。

3、代码

<el-table :data="employeesData" style="width:100%;height:100%;" :header-cell-style={background:'#fff'}" align="center">
       <el-table-column align="left" prop="name" label="员工姓名">
                  <template slot-scope="scope">
                    <span v-if="scope.row.name[2]">
                      <el-button
                        class="name-btn"
                        type="primary"
                      >{{ scope.row.name[1] }}{{ scope.row.name[2] }}</el-button>
                    </span>
                    <span v-else>
                      <el-button
                        class="name-btn"
                        type="primary"
                      >{{ scope.row.name[0] }}{{ scope.row.name[1] }}</el-button>
                    </span>
                    <span>{{ scope.row.name }}</span>
                  </template>
         </el-table-column>
         <el-table-column align="left" prop="mobile" label="手机号码"></el-table-column>
         <el-table-column align="left" prop="department" label="所属部门"></el-table-column>
                
      </el-table>

数据如下:

data() {
    return {
      employeesData: [
        {
          name: "王小明",
          mobile: "13900008789",
          department: "研发中心",
        },
        {
          name: "陈霞",
          mobile: "13900008789",
          department: "研发中心",
        }
      ] 
    }
  }

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值