vue.runtime.esm.js:3104 TypeError: dateObject.getTime is not a function

54 阅读1分钟

使用 element ui 时间组件设置 value-format="yyyy-MM-dd"后,出现了vue.runtime.esm.js:3104 TypeError: dateObject.getTime is not a function错误,

代码块:

image.png

错误信息:

image.png

错误分析:

date-picker 原本返回的是 Date 对象,通过 value-format 将 Date 转为了字符串。但是在我又设置了表单校验,表单校验需要获取到 Date 对象的 getTime 方法来进行校验,这个时候已经找不到 getTime 方法,所以报错。