el-table <template slot=“header“>不更新问题

<el-table-column
      v-for="(v, i) in dateHeader"
      :key="i"
      align="center"
      width="100"
    >
      <template slot="header">
        <div>{{ v.date | moment("MM-DD") }}</div>
        <div>{{ $moment(v.date).weekday() | formatWeek }}</div>
      </template>
      <template slot-scope="{ row }">
          <span
            v-if="row[v.prop]"
            class="el-icon-check"
            style="color:#0095ff;font-weight: bold"
          ></span>
        <span v-else></span>
      </template>
    </el-table-column>

控制台打印 数据没问题 已经更新了

找了好多 说是需要<template slot="header">改为#header=“scope” 我改了之后,没有效果,最后发现是因为:key的问题,最好不要使用index做key,表头部分用v-for循环生成的,给每个item(el-table-colum)绑定的key为prop,数据更新时,key没有变,所以el-table觉得表头数据是没有变化的,因此就只更新了整体表格数据、key值有变化的列的表头。

所以,key使用唯一的值就好了

<el-table-column
				v-for="i in dateHeader"
				:key="i.date"
				align="center"
				width="100"
			>
				<template slot="header">
					<div>{{ i.date | moment("MM-DD") }}</div>
					<div>{{ $moment(i.date).weekday() | formatWeek }}</div>
				</template>
				<template slot-scope="{ row }">
					<span
						v-if="row[i.prop]"
						class="el-icon-check"
						style="color: #0095ff; font-weight: bold"
					></span>
					<span v-else></span>
				</template>
			</el-table-column>
  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
你可以尝试在表头中添加图标或者字体图标,让它更加显眼。例如,可以在考核指标列的表头单元格中添加一个 `el-icon-warning-outline` 的图标,表示这一列是比较重要的内容;在考核周期列的表头单元格中添加一个 `el-icon-date` 的图标,表示这一列是和日期相关的内容。同时,你也可以尝试添加一些过渡效果,比如当鼠标悬停在单元格上时,让单元格的背景色变化,增加一些交互效果。下面是一个例子: ``` <template> <el-container style="height: 100%"> <el-table :data="tableData" style="width: 100%"> <el-table-column prop="index" label="考核指标" :header-cell-style="{backgroundColor: '#ff0000'}" width="110"> <template slot="header"> <i class="el-icon-warning-outline"></i> 考核指标 </template> </el-table-column> <el-table-column prop="ymatter" label="具体事项(原)" :header-cell-style="{backgroundColor: '#00ff00'}"></el-table-column> <el-table-column label="具体事项(新)" prop="xmatter"> <el-table-column prop="point" label="考核要点"></el-table-column> <el-table-column prop="method" label="计分方法"></el-table-column> <el-table-column prop="target" label="考核目标" width="200"></el-table-column> </el-table-column> <el-table-column prop="cycle" label="考核周期" :header-cell-style="{backgroundColor: '#0000ff'}" width="50"> <template slot="header"> <i class="el-icon-date"></i> 考核周期 </template> </el-table-column> </el-table> </el-container> </template> <style> .el-table__row:hover { background-color: #f5f5f5; } </style> ``` 这个例子中,我们在考核指标列和考核周期列的表头中分别添加了一个图标和文字,让它们更加显眼。同时,在 CSS 中定义了当鼠标悬停在单元格上时,单元格的背景色变成浅灰色,增加了一些过渡效果。你可以根据需要修改图标和颜色等样式,或添加其他交互效果。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值