diff --git a/demo/index.html b/demo/index.html index ebbe9e7..df81cc2 100644 --- a/demo/index.html +++ b/demo/index.html @@ -88,7 +88,7 @@

calendar

:days-disabled-end="daysDisabledEnd" :disabled-func="disabledFunc" :first-day-of-week="1" - :sync-date.sync="date" + v-model="date" :lang="lang" @change="onChange"> @@ -179,7 +179,7 @@

date-range

class="calendar" :days-disabled-start="daysDisabledStart" :days-disabled-end="daysDisabledEnd" - :sync-range="range" + v-model="range" :lang="lang" @change="onChange"> @@ -213,7 +213,6 @@

date-range

}, setRange (p) { if (typeof p === 'number') { - console.log(p) this.range = { startDate: moment().add(p, 'days'), endDate: moment() @@ -264,7 +263,6 @@

custom style

daysDisabledEnd: moment('2017-06-16'), disabledFunc: function (dayMoment) { var date = dayMoment.date() - console.log(date) if (date % 2 === 1) { return true } @@ -340,7 +338,6 @@

custom style

}, setRange (p) { if (typeof p === 'number') { - console.log(p) this.range = { startDate: moment().add(p, 'days'), endDate: moment() diff --git a/package.json b/package.json index 140cc8d..5773daa 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "vue-date-range", - "version": "2.2.1", - "description": "A vue component for choosing dates and date ranges. Uses Moment.js for date operations.", + "version": "2.2.2", + "description": "A vue component for choosing dates and date ranges. Uses Moment.js for date operations. Support Chinese lunar.", "main": "dist/vue-date-range.min.js", "scripts": { "test": "karma start --single-run", diff --git a/readme.md b/readme.md index a64d5a1..322ca0c 100644 --- a/readme.md +++ b/readme.md @@ -18,7 +18,7 @@ A vue component for choosing dates and date ranges. Uses Moment.js for date oper :show-lunar="true" :first-day-of-week="1" :disable-days-before-today="disableDaysBeforeToday" - :default-date="date" + :sync-date.sync="date" :lang="lang" @change="onChange"> ... import {Calendar} from 'vue-date-range'; @@ -43,7 +43,7 @@ export default { ### DateRange ``` - + ... import {DateRange} from 'vue-date-range'; export default { @@ -158,8 +158,15 @@ Download vue-date-range.min.js from dist/ and import in your web page. Example: # .sync For Vue2.3.0+, we can use [`.sync` modifier](https://vuejs.org/v2/guide/components.html#sync-Modifier): ```javascript - - + + +``` + +# v-model +We can also use [`v-model` modifier](https://vuejs.org/v2/guide/components.html#Form-Input-Components-using-Custom-Events) (these can be configured in 2.2.0+): +```javascript + + ``` # Props @@ -213,7 +220,7 @@ For Vue2.3.0+, we can use [`.sync` modifier](https://vuejs.org/v2/guide/componen * sync-date: The default selected date. Can be used as the “two-way binding” for date (Vue 2.3.0+). e.g.: ```html - + ``` * ~~default-date: Init the selected date. Only for Calendar.~~(use syncDate instead) * range: The selected date range. e.g.: @@ -228,6 +235,6 @@ Also it has its specific props: * sync-range: The default date range. Can be used as the “two-way binding” for range (Vue 2.3.0+). e.g.: ```html - + ``` * ~~defaultRange: Used to init the date range~~ diff --git a/src/Calendar.vue b/src/Calendar.vue index 93cd2c7..007e908 100644 --- a/src/Calendar.vue +++ b/src/Calendar.vue @@ -79,6 +79,9 @@ // }, syncDate: { type: Object + }, + value: { + type: Object } }, data () { @@ -99,6 +102,10 @@ syncDate (val) { this.date = val this.resetDayOfMonth() + }, + value (val) { + this.date = val + this.resetDayOfMonth() } }, created () { @@ -216,7 +223,9 @@ }, handleDayClick (day) { this.date = day.dayMoment + // to support three ways to get value this.$emit('update:syncDate', day.dayMoment) + this.$emit('input', day.dayMoment) this.$emit('change', day.dayMoment) }, changeMonth (delta) { diff --git a/src/DateRange.vue b/src/DateRange.vue index e2f1dd3..c10050a 100644 --- a/src/DateRange.vue +++ b/src/DateRange.vue @@ -57,6 +57,9 @@ // } syncRange: { type: Object + }, + value: { + type: Object } }, data () { @@ -73,6 +76,10 @@ syncRange (val) { this.rangeData = val this.step = 0 + }, + value (val) { + this.rangeData = val + this.step = 0 } }, methods: { @@ -97,7 +104,9 @@ const eTs = this.rangeData.endDate.unix() const startDate = sTs <= eTs ? this.rangeData.startDate : this.rangeData.endDate const endDate = sTs > eTs ? this.rangeData.startDate : this.rangeData.endDate + // to support three ways to get value this.$emit('update:syncRange', {startDate, endDate}) + this.$emit('input', {startDate, endDate}) this.$emit('change', {startDate, endDate}) } }