From cb16af03a57422614f0082fdf18f695aabfe60ff Mon Sep 17 00:00:00 2001 From: "qingwei.li" Date: Tue, 27 Sep 2016 11:12:11 +0800 Subject: [PATCH] DatePicker: fix initial value is string, #157 --- CHANGELOG.md | 1 + examples/docs/date-picker.md | 2 +- examples/docs/time-picker.md | 99 ++++++++++++++++++-------- packages/date-picker/src/util/index.js | 3 +- 4 files changed, 72 insertions(+), 33 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb784c01..2495a35b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - 修复 Menu 组件 default-active 绑定动态值无法更新的问题 - 新增特性 Menu 组件中若选中子菜单项现在会自动展开所有父级菜单 - 修复 vue-popper 引入 popper 路径错误 +- 修复 DatePicker 初始值是合法时间类型但无法设置成功的问题 #### 非兼容性更新 - Menu 组件的 `unique-opend` 属性修正为 `unique-opened` diff --git a/examples/docs/date-picker.md b/examples/docs/date-picker.md index 9f29bbb6..31fec90a 100644 --- a/examples/docs/date-picker.md +++ b/examples/docs/date-picker.md @@ -51,7 +51,7 @@ } }] }, - value1: '', + value1: '2016-08-10', value2: '', value3: '', value4: '', diff --git a/examples/docs/time-picker.md b/examples/docs/time-picker.md index 65776544..94eec0cc 100644 --- a/examples/docs/time-picker.md +++ b/examples/docs/time-picker.md @@ -34,13 +34,25 @@ :::demo 使用 el-time-picker 标签,通过`selectableRange`限制可选时间范围 ```html - - + + + ``` ::: @@ -50,25 +62,38 @@ :::demo ```html - - - - + + + ``` ::: @@ -78,11 +103,23 @@ :::demo 添加`is-range`属性即可选择时间范围 ```html - - + + + ``` ::: diff --git a/packages/date-picker/src/util/index.js b/packages/date-picker/src/util/index.js index 07936cfb..be1eed1e 100644 --- a/packages/date-picker/src/util/index.js +++ b/packages/date-picker/src/util/index.js @@ -25,7 +25,8 @@ export const merge = function(target) { }; export const formatDate = function(date, format) { - if (!(date instanceof Date)) return ''; + date = new Date(date); + if (isNaN(date.getTime())) return ''; return dateUtil.format(date, format || 'yyyy-MM-dd'); };