element-ui 表格数据时间格式化的方法

这篇文章主要介绍了element-ui 表格数据时间格式化的方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

后台返回时间格式  /1470220594000/

在element-ui  table 如何格式化呢 

1.首先

复制代码 代码如下:
 

主要是:formatter="dateFormat" 这个属性 

formatter 用来格式化内容 Function(row, column, cellValue, index)  

然后在   methods 方法对象里  添加 如下方法

 //时间格式化 dateFormat(row, column, cellValue, index){ const daterc = row[column.property] if(daterc!=null){ const dateMat= new Date(parseInt(daterc.replace("/Date(", "").replace(")/", ""), 10)); const year = dateMat.getFullYear(); const month = dateMat.getMonth() + 1; const day = dateMat.getDate(); const hh = dateMat.getHours(); const mm = dateMat.getMinutes(); const ss = dateMat.getSeconds(); const timeFormat= year + "/" + month + "/" + day + " " + hh + ":" + mm + ":" + ss; return timeFormat; } } 

格式化后:

2018/2/27 8:59:19

PS:Element UI的表格table列的宽度自适应设置

不要设置  width="110px"

   

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持html中文网。

以上就是element-ui 表格数据时间格式化的方法的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » Vue.js 教程