Skip to content

Commit a9417e4

Browse files
defccyyx990803
authored andcommitted
select change event fix (#3922)
* if select binding not changed, then needRest should be set to false, and no change event should be emitted * update code style
1 parent 443ef1c commit a9417e4

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/platforms/web/runtime/directives/model.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export default {
6060
// option in the DOM.
6161
const needReset = el.multiple
6262
? binding.value.some(v => hasNoMatchingOption(v, el.options))
63-
: hasNoMatchingOption(binding.value, el.options)
63+
: binding.value === binding.oldValue ? false : hasNoMatchingOption(binding.value, el.options)
6464
if (needReset) {
6565
trigger(el, 'change')
6666
}

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,32 @@ describe('Directive v-model select', () => {
161161
}).then(done)
162162
})
163163

164+
it('should work with select which has no default selected options', (done) => {
165+
const spy = jasmine.createSpy()
166+
const vm = new Vue({
167+
data: {
168+
id: 4,
169+
list: [1, 2, 3],
170+
testChange: 5
171+
},
172+
template:
173+
'<div>' +
174+
'<select @change="test" v-model="id">' +
175+
'<option v-for="item in list" :value="item">{{item}}</option>' +
176+
'</select>' +
177+
'{{testChange}}' +
178+
'</div>',
179+
methods: {
180+
test: spy
181+
}
182+
}).$mount()
183+
document.body.appendChild(vm.$el)
184+
vm.testChange = 10
185+
waitForUpdate(() => {
186+
expect(spy.calls.count()).toBe(0)
187+
}).then(done)
188+
})
189+
164190
it('multiple', done => {
165191
const vm = new Vue({
166192
data: {

0 commit comments

Comments
 (0)