我想在我的vue 3应用程序(https://moment.github.io/luxon/#/)中使用鲁迅
但不幸的是,它现在不支持vue3。这就是为什么我想用鲁迅包装我的应用程序,但我不知道如何准确地完成它。
因此,在我的组件中,我像这样导入了鲁迅:
import { DateTime } from 'luxon';
methods: {
getCurrentMonth() {
const currentMonth = DateTime().month() + 1;
return currentMonth;
}
}但是我收到了这样的错误: Uncaught (承诺) TypeError:类构造函数DateTime不能在没有“new”的情况下被调用
我认为这是因为我在vue3应用程序中使用/包装卢克松是错误的。
我怎么才能修好它?
发布于 2022-10-24 11:16:30
如果没有DateTime()关键字(以及配置参数,请参见文档),您就不能使用new。
我建议使用DateTime.now()来获取当前的日期和时间。此外,month是DateTime对象的成员,而不是方法。
您的代码可以如下所示:
import { DateTime } from 'luxon';
methods: {
getCurrentMonth() {
const currentMonth = DateTime.now().month + 1;
return currentMonth;
}
}https://stackoverflow.com/questions/74180168
复制相似问题