牛叔叔 的笔记

好好学习

2021-04-16 11:37

ElementUI时间线Timeline 实现同一天多个内容只显示一个时间

牛叔叔

WEB前端

(2261)

(0)

收藏

在使用ElementUI时间线组件时,希望在显示时间戳的时候,同一天的多个事件,只第一个事件显示时间戳,。

如图:

微信图片_20210416113154.png


在el-timeline组件中提供了一个属性:

hide-timestamp是否隐藏时间戳booleanfalse


如果我们在显示事件时,通过控制这个hide-timestamp值,即可实现我们所需要的效果。


具体实现代码如下:

                     <template v-for="log,index in logs">
                      <el-timeline-item :timestamp="log.realityTime" placement="top" 
                      :hide-timestamp="index>0&&(log.realityTime==logs[index-1].realityTime)">
                        <el-card class="log">
                          <h4>
                            事件标题
                          </h4>
                          <div v-html="log.info">
                          </div>

                        </el-card>
                      </el-timeline-item>
                      </template>



重点就是通过

:hide-timestamp="index>0&&(log.realityTime==logs[index-1].realityTime)

来计算当前时间戳是否显示,如果当前节点和上一个节点时间戳相同,则不显示。

0条评论

点击登录参与评论