Sfoglia il codice sorgente

DatePicker: supports default value

default-value sets a default value when picker opens
wacky6.AriesMBP 8 anni fa
parent
commit
3fe9acf294

+ 2 - 2
packages/date-picker/src/panel/date.vue

@@ -187,7 +187,7 @@
 
     methods: {
       handleClear() {
-        this.date = new Date();
+        this.date = this.$options.defaultValue ? new Date(this.$options.defaultValue) : new Date();
         this.$emit('pick');
       },
 
@@ -357,7 +357,7 @@
       return {
         popperClass: '',
         pickerWidth: 0,
-        date: new Date(),
+        date: this.$options.defaultValue ? new Date(this.$options.defaultValue) : new Date(),
         value: '',
         showTime: false,
         selectionMode: 'day',

+ 2 - 1
packages/date-picker/src/picker.vue

@@ -205,6 +205,7 @@ export default {
       default: 'left'
     },
     value: {},
+    defaultValue: {},
     rangeSeparator: {
       default: ' - '
     },
@@ -410,7 +411,7 @@ export default {
     showPicker() {
       if (this.$isServer) return;
       if (!this.picker) {
-        this.panel.defaultValue = this.currentValue;
+        this.panel.defaultValue = this.defaultValue || this.currentValue;
         this.picker = new Vue(this.panel).$mount();
         this.picker.popperClass = this.popperClass;
         this.popperElm = this.picker.$el;