项目场景:
提示:这里简述项目相关背景:
Error >>>>>>
index.js?ac5b:25 TypeError: dateObject.getTime is not a function
at Object.date [as validator] (date.js?eb4e:25)
at eval (index.js?4cb2:216)
at next (util.js?e3be:114)
at asyncSerialArray (util.js?e3be:120)
at eval (util.js?e3be:154)
at Array.forEach ()
at asyncMap (util.js?e3be:151)
at Schema.validate (index.js?4cb2:141)
at VueComponent.validate (element-ui.common.js?5c96:23519)
at VueComponent.onFieldBlur (element-ui.common.js?5c96:23586)
问题描述
问题如下:
开发项目时,需要按照客户需求开发指定的 日期形式,并 传值到后台,存入数据库。
前端 控制台 出现上述错误 信息。
原因分析:
分析:
根据报错日志信息我们大致可以 了解到 是和 时间有关,
所以我们首先查看开发的新页面中 使用及调用 日期或时间有关的 方法。
解决方案:
解决方法:
检查 传入的值是否 为 String 类型,将请求来的string类型日期通过new Date() 强制转换为date格式,再进行绑定,如下所示:
<el-form-item prop="useMonth" >
<el-date-picker
v-model="dataForm.useMonth"
type="month"
placeholder="选择月"
style="font-size:15px;"
size="50px"
@change="changeUseMonth"
clearable>
</el-date-picker>
</el-form-item>
changeUseMonth(useMonth){
this.useMonthFormatter(useMonth);
},
useMonthFormatter() {
if (this.dataForm.useMonth) {
var scrap = new Date(this.dataForm.useMonth);
var scrapYear = scrap.getFullYear();
var scrapMonth = scrap.getMonth() + 1; //js从0开始取
this.useMonth = scrapYear + "年" + scrapMonth + "月";
}
},
注意: 在使用 有关时间的 组件及控件时,一定要特别注意 我们使用的数值的 类型及 需要接收 和传输的值的类型。
确保使用过程中 不会出现上述问题。