From 9737d1b1bd075f1ead3ac3a02de39e1ee9cfccac Mon Sep 17 00:00:00 2001 From: misoguy Date: Thu, 26 Oct 2017 23:02:02 +0900 Subject: [PATCH 1/3] Add test to verify bug reported in issue #6918 --- .../features/directives/model-dynamic.spec.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/unit/features/directives/model-dynamic.spec.js b/test/unit/features/directives/model-dynamic.spec.js index eb193f19bdf..46f940ff232 100644 --- a/test/unit/features/directives/model-dynamic.spec.js +++ b/test/unit/features/directives/model-dynamic.spec.js @@ -40,6 +40,23 @@ describe('Directive v-model dynamic input type', () => { assertInputWorks(vm, chain).then(done) }) + it('with v-else', done => { + const data = { + ok: true, + type: null, + test: 'b' + } + const vm = new Vue({ + data, + template: `
haha
` + }).$mount() + document.body.appendChild(vm.$el) + expect(vm.$el.textContent).toBe('haha') + + vm.ok = false + assertInputWorks(vm).then(done) + }) + it('with v-for', done => { const vm = new Vue({ data: { From 052c53a28a9b3b7592f0befd8f24f7f9ef5ec325 Mon Sep 17 00:00:00 2001 From: Soo Jae Hwang Date: Mon, 30 Oct 2017 12:17:54 +0900 Subject: [PATCH 2/3] Add Implementation to fix issue #6918 --- src/platforms/web/compiler/modules/model.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/platforms/web/compiler/modules/model.js b/src/platforms/web/compiler/modules/model.js index 61657d1fa43..6bad91b8b16 100644 --- a/src/platforms/web/compiler/modules/model.js +++ b/src/platforms/web/compiler/modules/model.js @@ -29,6 +29,7 @@ function preTransformNode (el: ASTElement, options: CompilerOptions) { const typeBinding: any = getBindingAttr(el, 'type') const ifCondition = getAndRemoveAttr(el, 'v-if', true) const ifConditionExtra = ifCondition ? `&&(${ifCondition})` : `` + const hasElse = getAndRemoveAttr(el, 'v-else', true) != null // 1. checkbox const branch0 = cloneASTElement(el) // process for on the main node @@ -59,6 +60,11 @@ function preTransformNode (el: ASTElement, options: CompilerOptions) { exp: ifCondition, block: branch2 }) + + if (hasElse) { + branch0.else = true + } + return branch0 } } From c2b52ac91890c700d0efaf6f7baf257994bfed6f Mon Sep 17 00:00:00 2001 From: gebilaoxiong Date: Mon, 30 Oct 2017 15:20:51 +0800 Subject: [PATCH 3/3] fix(model): fix dynamic v-model with v-else-if statement --- src/platforms/web/compiler/modules/model.js | 3 +++ .../features/directives/model-dynamic.spec.js | 25 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/platforms/web/compiler/modules/model.js b/src/platforms/web/compiler/modules/model.js index 6bad91b8b16..5e882d72545 100644 --- a/src/platforms/web/compiler/modules/model.js +++ b/src/platforms/web/compiler/modules/model.js @@ -30,6 +30,7 @@ function preTransformNode (el: ASTElement, options: CompilerOptions) { const ifCondition = getAndRemoveAttr(el, 'v-if', true) const ifConditionExtra = ifCondition ? `&&(${ifCondition})` : `` const hasElse = getAndRemoveAttr(el, 'v-else', true) != null + const elseIfCondition = getAndRemoveAttr(el, 'v-else-if', true) // 1. checkbox const branch0 = cloneASTElement(el) // process for on the main node @@ -63,6 +64,8 @@ function preTransformNode (el: ASTElement, options: CompilerOptions) { if (hasElse) { branch0.else = true + } else if (elseIfCondition) { + branch0.elseif = elseIfCondition } return branch0 diff --git a/test/unit/features/directives/model-dynamic.spec.js b/test/unit/features/directives/model-dynamic.spec.js index 46f940ff232..a5c18fe82b2 100644 --- a/test/unit/features/directives/model-dynamic.spec.js +++ b/test/unit/features/directives/model-dynamic.spec.js @@ -57,6 +57,31 @@ describe('Directive v-model dynamic input type', () => { assertInputWorks(vm).then(done) }) + it('with v-else-if', done => { + const vm = new Vue({ + data: { + foo: true, + bar: false, + type: null, + test: 'b' + }, + template: `
text
` + }).$mount() + document.body.appendChild(vm.$el) + + const chain = waitForUpdate(() => { + expect(vm.$el.textContent).toBe('text') + }).then(() => { + vm.foo = false + }).then(() => { + expect(vm._vnode.isComment).toBe(true) + }).then(() => { + vm.bar = true + }) + + assertInputWorks(vm, chain).then(done) + }) + it('with v-for', done => { const vm = new Vue({ data: {