【发布时间】:2020-01-28 19:33:05
【问题描述】:
我的 VueJs 页面中有一个数据表,并通过 ajax 请求获取其数据。返回数据是这样的
{
name: "Test Name",
created_at: "2019-06-14 07:31:15"
}
我的按钮应该使用以下规则过滤数据:
Created data within the last 5 mins
Created data within the last 15 mins
Created data within the last 30 mins
鉴于我的created_at,我该怎么做?我有这个当前功能
computed: {
filterData() {
return this.customers.filter(item => item.created_at.includes(new Date().getDay()+1));
}
}
数据this.customers是我的ajax请求数据。
我只是从这里引用它 filter response data date wise vue 。基于此,我希望数据被 1 天前的数据过滤。但这对我也不起作用。也许是因为我的日期是日期时间而不是日期?
【问题讨论】:
-
我认为您需要的是一个库来为您执行此操作,请尝试使用以下功能:momentjscom.readthedocs.io/en/latest/moment/04-displaying/…
-
我同意@kaushik94,使用矩库。
-
感谢大家的建议,但我不喜欢使用 moment 或加载另一个库来计算分钟数。
标签: javascript datetime vue.js time filter