【发布时间】:2021-11-14 00:12:26
【问题描述】:
我正在尝试查找星期几。所以为此我的功能是:
getWeekNumber(date) {
const temp_date = new Date(date.valueOf());
const dayn = (date.getDay() + 6) % 7;
temp_date.setDate(temp_date.getDate() - dayn + 3);
const firstThursday = temp_date.valueOf();
temp_date.setMonth(0, 1);
if (temp_date.getDay() !== 4) {
temp_date.setMonth(0, 1 + ((4 - temp_date.getDay() + 7) % 7));
}
return 1 + Math.ceil((firstThursday - temp_date) / 604800000);
},
我正在其他功能中使用此功能来查找产品:
findProducts(products, date) {
return products.filter((product) => {
const formated_date = this.setDateFormat(product.attributes.date);
console.log(formated_date);
console.log(formated_date.valueOf());
return (
formated_date.getDate() === date.getDate() &&
formated_date.getMonth() === date.getMonth() &&
formated_date.getFullYear() === date.getFullYear() &&
this.getWeekNumber(formated_date) === this.currentWeekNumber
);
});
},
但我的问题是在控制台中的 findProducts 函数内部,我可以看到如下输出: 2021 年 9 月 28 日星期二 02:00:00 GMT+0200(中欧夏令时间) 表.vue:144 1632787200000
但是每当它转到 getWeekNumber 函数时,我都会收到此错误: vue.esm.js:1897 TypeError: Cannot read properties of undefined (reading 'valueOf')
你知道为什么会这样吗?
谢谢...
【问题讨论】:
标签: vue.js date vuejs2 value-of