From a9417e4e4fcb91d445c15d79b6eec684d7e5c9c7 Mon Sep 17 00:00:00 2001 From: defcc Date: Thu, 13 Oct 2016 01:26:42 +0800 Subject: [PATCH] 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 --- src/platforms/web/runtime/directives/model.js | 2 +- .../features/directives/model-select.spec.js | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/platforms/web/runtime/directives/model.js b/src/platforms/web/runtime/directives/model.js index 0c67c9ab..f6c24eea 100644 --- a/src/platforms/web/runtime/directives/model.js +++ b/src/platforms/web/runtime/directives/model.js @@ -60,7 +60,7 @@ export default { // option in the DOM. const needReset = el.multiple ? binding.value.some(v => hasNoMatchingOption(v, el.options)) - : hasNoMatchingOption(binding.value, el.options) + : binding.value === binding.oldValue ? false : hasNoMatchingOption(binding.value, el.options) if (needReset) { trigger(el, 'change') } diff --git a/test/unit/features/directives/model-select.spec.js b/test/unit/features/directives/model-select.spec.js index 9b6092f2..dad45168 100644 --- a/test/unit/features/directives/model-select.spec.js +++ b/test/unit/features/directives/model-select.spec.js @@ -161,6 +161,32 @@ describe('Directive v-model select', () => { }).then(done) }) + it('should work with select which has no default selected options', (done) => { + const spy = jasmine.createSpy() + const vm = new Vue({ + data: { + id: 4, + list: [1, 2, 3], + testChange: 5 + }, + template: + '
' + + '' + + '{{testChange}}' + + '
', + methods: { + test: spy + } + }).$mount() + document.body.appendChild(vm.$el) + vm.testChange = 10 + waitForUpdate(() => { + expect(spy.calls.count()).toBe(0) + }).then(done) + }) + it('multiple', done => { const vm = new Vue({ data: {