Skip to content

Commit 63c208d

Browse files
posvahefeng
authored and
hefeng
committed
fix(shared): check dates in looseEqual (vuejs#7940)
Fix vuejs#7928 thanks to @w3cj for the initial version. This one is using getTime instead of toUTCString because it is much faster to compare
1 parent 172c5fb commit 63c208d

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/shared/util.js

+2
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ export function looseEqual (a: any, b: any): boolean {
286286
return a.length === b.length && a.every((e, i) => {
287287
return looseEqual(e, b[i])
288288
})
289+
} else if (a instanceof Date && b instanceof Date) {
290+
return a.getTime() === b.getTime()
289291
} else if (!isArrayA && !isArrayB) {
290292
const keysA = Object.keys(a)
291293
const keysB = Object.keys(b)

test/unit/features/directives/model-select.spec.js

+27
Original file line numberDiff line numberDiff line change
@@ -588,4 +588,31 @@ describe('Directive v-model select', () => {
588588
}).then(done)
589589
})
590590
})
591+
592+
// #7928
593+
it('should correctly handle option with date value', done => {
594+
const vm = new Vue({
595+
data: {
596+
dates: [
597+
new Date(1520000000000),
598+
new Date(1522000000000),
599+
new Date(1516000000000)
600+
],
601+
selectedDate: null
602+
},
603+
template:
604+
'<div>' +
605+
'<select v-model="selectedDate">' +
606+
'<option v-for="(date, i) in dates" :key="i" :value="date">' +
607+
'{{date}}' +
608+
'</option>' +
609+
'</select>' +
610+
'</div>'
611+
}).$mount()
612+
613+
vm.selectedDate = vm.dates[2]
614+
waitForUpdate(() => {
615+
expect(vm.$el.firstChild.selectedIndex).toBe(2)
616+
}).then(done)
617+
})
591618
})

0 commit comments

Comments
 (0)