From f4eb76daf4e881d97e24ee111533925b048e1d17 Mon Sep 17 00:00:00 2001 From: GU Yiling Date: Thu, 8 Mar 2018 06:44:55 +0800 Subject: [PATCH] fix: skip v-model & value binding collision check with dynamic type binding (#7406) * fix #7404 --- src/platforms/web/compiler/directives/model.js | 4 +++- test/unit/features/directives/model-text.spec.js | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/platforms/web/compiler/directives/model.js b/src/platforms/web/compiler/directives/model.js index 2533ba3560f..fc33a0c6e45 100644 --- a/src/platforms/web/compiler/directives/model.js +++ b/src/platforms/web/compiler/directives/model.js @@ -130,9 +130,11 @@ function genDefaultModel ( const type = el.attrsMap.type // warn if v-bind:value conflicts with v-model + // except for inputs with v-bind:type if (process.env.NODE_ENV !== 'production') { const value = el.attrsMap['v-bind:value'] || el.attrsMap[':value'] - if (value) { + const typeBinding = el.attrsMap['v-bind:type'] || el.attrsMap[':type'] + if (value && !typeBinding) { const binding = el.attrsMap['v-bind:value'] ? 'v-bind:value' : ':value' warn( `${binding}="${value}" conflicts with v-model on the same element ` + diff --git a/test/unit/features/directives/model-text.spec.js b/test/unit/features/directives/model-text.spec.js index 77a9e3d8d02..08bd1efc92a 100644 --- a/test/unit/features/directives/model-text.spec.js +++ b/test/unit/features/directives/model-text.spec.js @@ -289,6 +289,17 @@ describe('Directive v-model text', () => { expect('conflicts with v-model').not.toHaveBeenWarned() }) + it('should not warn on input with dynamic type binding', () => { + new Vue({ + data: { + type: 'checkbox', + test: 'foo' + }, + template: '' + }).$mount() + expect('conflicts with v-model').not.toHaveBeenWarned() + }) + if (!isAndroid) { it('does not trigger extra input events with single compositionend', () => { const spy = jasmine.createSpy()