From f8a665d463d89705547ec0dad8b4cbad31cafa58 Mon Sep 17 00:00:00 2001 From: defcc Date: Thu, 13 Oct 2016 00:20:05 +0800 Subject: [PATCH 1/2] if select binding not changed, then needRest should be set to false, and no change event should be emitted --- 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 0c67c9abf46..f6c24eea3c3 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 9b6092f26e1..95879b629d6 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: { From 3484cf768198e650b5b47872fa3f23eefec9affa Mon Sep 17 00:00:00 2001 From: defcc Date: Thu, 13 Oct 2016 00:22:25 +0800 Subject: [PATCH 2/2] update code style --- test/unit/features/directives/model-select.spec.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/unit/features/directives/model-select.spec.js b/test/unit/features/directives/model-select.spec.js index 95879b629d6..dad451687d3 100644 --- a/test/unit/features/directives/model-select.spec.js +++ b/test/unit/features/directives/model-select.spec.js @@ -166,16 +166,16 @@ describe('Directive v-model select', () => { const vm = new Vue({ data: { id: 4, - list: [1,2,3], + list: [1, 2, 3], testChange: 5 }, template: - '
' + - '' + - '{{testChange}}' + - '
', + '
' + + '' + + '{{testChange}}' + + '
', methods: { test: spy }