Uncaught (in promise) TypeError: x.isoWeek is not a function
在 vue3 项目开发中,引入 dayjs 插件后,使用 isoWeek() 浏览器提示错误:
Uncaught (in promise) TypeError: x.isoWeek is not a function
解决方案
要想使用
isoWeek()
API,就需要引入插件扩展包(dayjs/plugin/isoWeek
),如下代码(引入+使用)所示:
// 引入基础包
import dayjs from 'dayjs'// 引入并初始化 "周处理" 的扩展包
import isoWeek from 'dayjs/plugin/isoWeek'
dayjs.extend(isoWeek)const today = dayjs();
const currentWeekNumber = today.isoWeek();
console.log(`Current week number (ISO): ${currentWeekNumber}`);