Vuetify日历加载时抛出时间戳无效错误求助
解决Vuetify日历的"无效时间戳"错误
问题根源
错误提示里的2022-09-14 带有多余空格,说明你拼接的start字符串存在无效空格——大概率是fD['startTime']为空字符串/未定义,或者本身带前后空格,导致拼接后变成YYYY-MM-DD (两个空格),不符合Vuetify要求的格式规范。
修复方案
1. 清理字符串空格
对拼接后的start做去空格处理,确保格式严格合规:
const scheduleDate = new Date(fD['scheduleDate']).toISOString().slice(0,10) const start = `${scheduleDate} ${fD['startTime'] || ''}`.trim()
2. 先校验startTime有效性
避免空值导致的无效拼接:
const scheduleDate = new Date(fD['scheduleDate']).toISOString().slice(0,10) let start = scheduleDate; // 仅当startTime有有效值时才执行拼接 if (fD['startTime']?.trim()) { start = `${scheduleDate} ${fD['startTime'].trim()}`; }
3. 用Date对象替代字符串(更可靠)
直接构造Date对象传给Vuetify,完全规避字符串格式问题:
const scheduleDate = new Date(fD['scheduleDate']).toISOString().slice(0,10) const startDate = new Date(scheduleDate); // 解析startTime并设置时分 if (fD['startTime']) { const [hours, minutes] = fD['startTime'].split(':'); startDate.setHours(parseInt(hours, 10), parseInt(minutes, 10)); } const event = { color: color, name: 'meeting', date: scheduleDate, start: startDate, // 直接传入Date对象 }
内容的提问来源于stack exchange,提问作者mikeym
相关产品推荐
相关产品推荐

