当前位置: 首页 > 工具软件 > ngx-ui > 使用案例 >

使用Element-UI的DateTimePicker组件报错:Cannot read property 'getHours' of undefined

邓阳嘉
2023-12-01

在使用 Element-UI 的 DateTimePicker 组件时报错: TypeError: Cannot read property 'getHours' of undefined

具体错误如下:

TypeError: Cannot read property 'getHours' of undefined
    at o.hours (index.js:1)
    at St.get (vue.min.js:6)
    at St.evaluate (vue.min.js:6)
    at o.hours (vue.min.js:6)
    at index.js:1
    at o.Pt [as _l] (vue.min.js:6)
    at o.n (index.js:1)
    at o.fn._render (vue.min.js:6)
    at o.<anonymous> (vue.min.js:6)
    at St.get (vue.min.js:6)

错误原因:

date-picker 的时间是格林威时间,如 Thu Jun 22 2019 17:10:30 GMT+0800,然而我们却用的是时间字符串:2019-06-22 17:10:30 或时间戳的格式去绑定 date-picker,因此就会报以上错误。

解决方案:

将v-model绑定的时间转换成格林威时间Thu Jun 22 2019 17:10:30 GMT+0800即可!转换很简单,只需new Date()一下就可以了。this.data.startTime = new Date(this.data.startTime)

 

 

 

 

 类似资料: