From f4da78a555c255a2f6b84207fc830e7a8469492c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Sanchez?= Date: Thu, 16 Jun 2016 14:55:05 +0200 Subject: [PATCH] Safely parse value in template --- src/Datepicker.vue | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Datepicker.vue b/src/Datepicker.vue index 2ee35d97..20c12047 100644 --- a/src/Datepicker.vue +++ b/src/Datepicker.vue @@ -56,8 +56,8 @@
@@ -76,7 +76,7 @@
@@ -131,6 +131,11 @@ export default { ] } }, + computed: { + parsedValue() { + return this.parse(this.value) || this.parse(new Date()); + } + }, watch: { currDate() { this.getDateRange() @@ -315,7 +320,7 @@ export default { if (i === time.day) { if (this.value) { - const valueDate = this.parse(this.value) + const valueDate = this.parsedValue if (valueDate) { if (valueDate.getFullYear() === time.year && valueDate.getMonth() === time.month) { sclass = 'datepicker-dateRange-item-active' @@ -346,7 +351,7 @@ export default { }, ready() { this.$dispatch('child-created', this) - this.currDate = this.parse(this.value) || this.parse(new Date()) + this.currDate = this.parsedValue || this.parse(new Date()) this._closeEvent = EventListener.listen(window, 'click', (e)=> { if (!this.$el.contains(e.target)) this.close() })