必须收藏Vue之时间过滤器,你确定不来看看吗
2020-07-24 18:47
155 查看
#1.1 Vue.filter 定义一个全局过滤器 Vue.filter('format', function(value, arg) { function dateFormat(date, format) { if (typeof date === "string") { var mts = date.match(/(\/Date\((\d+)\)\/)/); if (mts && mts.length >= 3) { date = parseInt(mts[2]); } } date = new Date(date); if (!date || date.toUTCString() == "Invalid Date") { return ""; } var map = { "M": date.getMonth() + 1, //月份 "d": date.getDate(), //日 "h": date.getHours(), //小时 "m": date.getMinutes(), //分 "s": date.getSeconds(), //秒 "q": Math.floor((date.getMonth() + 3) / 3), //季度 "S": date.getMilliseconds() //毫秒 }; format = format.replace(/([yMdhmsqS])+/g, function(all, t) { var v = map[t]; if (v !== undefined) { if (all.length > 1) { v = '0' + v; v = v.substr(v.length - 2); } return v; } else if (t === 'y') { return (date.getFullYear() + '').substr(4 - all.length); } return all; }); return format; } return dateFormat(value, arg); }) <!-- 直接在时间旁边调用过滤器即可 参数为时间格式 --> <td>{{item.date | format('yyyy-MM-dd hh:mm:ss')}}</td>
相关文章推荐
- vue实现自定义过滤器之时间格式自定义
- Vue 使用过滤器实现将时间戳转日期格式
- vue过滤器--格式化时间
- vue中格式化时间过滤器代码实例
- Vue教程09(过滤器应用-时间格式字符串格式化)
- vue v-for 获取了一个时间戳, 然后加过滤器, 变成了NaN-NaN-NaN,为什么?
- Vue的时间过滤器(毫秒转化为年月日时分秒的形式)
- Vue 2.0 时间过滤器
- vue用过滤器对后端的返回的时间做处理,并使用.padStart()方法
- vue学习十二----过滤器(采用 私有/公有对 new Date()时间格式转化)
- vue时间过滤器,过滤器使用
- vue的时间过滤器
- 教女朋友学习 vue中的过滤器及其时间格式化
- vue时间过滤器,更改时间格式
- vue 时间戳转日期格式的过滤器
- 关于vue中自定义时间戳和金钱的过滤器
- vue2.0 自定义日期时间过滤器
- vue中的过滤器及其时间格式化问题
- Vue使用时间过滤器
- vue时间过滤器