Skip to content

Commit ff77a22

Browse files
committed
update date-picker
1 parent 008e692 commit ff77a22

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

example/components/date-picker.vue

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,14 @@
3939
},
4040
data() {
4141
return {
42-
tempIndex: [0, 0, 0]
42+
tempIndex: [0, 0, 0],
43+
values: [0, 0, 0]
4344
}
4445
},
46+
mounted() {
47+
this.values = [this.years[this.selectedIndex[0]], this.month[this.selectedIndex[1]], this.day[this.selectedIndex[2]]]
48+
this.tempIndex = this.selectedIndex
49+
},
4550
computed: {
4651
years() {
4752
return range(this.min[0], this.max[0], false, '')
@@ -67,15 +72,19 @@
6772
6873
let minDay = !this.tempIndex[0] && !this.tempIndex[1] ? this.min[2] : 1
6974
let maxDay = this.tempIndex[0] === this.years.length - 1 && this.tempIndex[1] === this.months.length - 1 ? this.max[2] : day
75+
let days = range(minDay, maxDay, false, '')
76+
77+
this.$refs.picker.setData([this.years, this.months, this.days], this.tempIndex)
7078
71-
return range(minDay, maxDay, false, '')
79+
return days
7280
},
7381
dateData() {
7482
return [this.years, this.months, this.days]
7583
}
7684
},
7785
watch: {
78-
dateData() {
86+
days() {
87+
this.$refs.picker.setData(this.dateData, [this.yearIndex, this.monthIndex, this.dayIndex])
7988
this.$refs.picker.refresh()
8089
}
8190
},
@@ -89,7 +98,9 @@
8998
change(i, newIndex) {
9099
if (newIndex !== this.tempIndex[i]) {
91100
this.tempIndex.splice(i, 1, newIndex)
92-
this.$refs.picker.setData(this.dateData, this.tempIndex)
101+
}
102+
if (this.dateData[i][newIndex] !== this.value[i]) {
103+
this.values.splice(i, 1, this.dateData[i][newIndex])
93104
}
94105
},
95106
select(selectedVal, selectedIndex, selectedText) {

0 commit comments

Comments
 (0)