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
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值