【发布时间】:2019-10-06 00:00:12
【问题描述】:
在一个 Vuejs 应用程序中,我目前有一个每天可用一次的按钮。单击一次后,它将被禁用,直到第二天。这在本地运行良好,但在 heroku 上,比较似乎不起作用。
这是 vue 组件中的 y 日期计算值,如果 Act 是在当前日期 00:00 之后创建的,则返回 true:
computed: {
...
actedToday() {
if (!!this.$store.getters.lastAct) {
let now = new Date();
console.log('this is now in actedToday computed: ', now);
let lastActDate = new Date(this.$store.getters.lastAct.created_at);
console.log('this is last act date in computed actedToday', this.$store.getters.lastAct.created_at);
console.log('was last Act today? ', lastActDate.getTime() > now.setHours(0,0,0,0));
return lastActDate.getTime() > now.setHours(0,0,0,0)
}
}
},
这是 console.log 在本地返回的内容:
this is now in actedToday computed: Fri Oct 04 2019 15:20:24 GMT-0400 (Eastern Daylight Time)
ActButton.vue?0bb7:31 this is last act date in computed actedToday 2019-10-04T19:20:23.901Z
ActButton.vue?0bb7:32 was last Act today? true
这是来自 heroku 应用程序的类似日志:
this is now in actedToday computed: Fri Oct 04 2019 15:21:18 GMT-0400 (Eastern Daylight Time)
ActButton.vue:31 this is last act date in computed actedToday 2019-10-04T03:30:22.266Z
ActButton.vue:32 was last Act today? false
在第一个示例中,比较按预期进行。第二种,虽然两个日期在同一天,但比较返回false。
【问题讨论】: