VUE 格式化时间 兼容移动PC端
作者:
一只菜鸟正在脱毛 | 来源:发表于
2020-06-08 14:04 被阅读0次移动端打开 时间格式错乱

image.png
解决步骤:
一、安装依赖包
npm install moment --save
二、main.js引入
import moment from 'moment'
//定义一个全局过滤器实现日期格式化
Vue.prototype.formatIosDate = function (date) {
return moment(date).format('YYYY/MM/DD HH:mm:ss')
}
三、在需要格式化时间的方法里写入

image.png
that.TopNewsList.forEach(function(v) {
v.create_time = new Date(
that.formatIosDate(v.create_time)
).Format("yyyy-MM-dd hh:mm:ss");
});
that.NewsList.forEach(function(v) {
v.create_time = new Date(
that.formatIosDate(v.create_time)
).Format("yyyy-MM-dd hh:mm:ss");
});
本文标题:VUE 格式化时间 兼容移动PC端
本文链接:https://www.haomeiwen.com/subject/zmyltktx.html
网友评论