Skip to content

Commit f4eb76d

Browse files
Justineohefeng
authored and
hefeng
committed
fix: skip v-model & value binding collision check with dynamic type binding (vuejs#7406)
* fix vuejs#7404
1 parent ed8537d commit f4eb76d

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,11 @@ function genDefaultModel (
130130
const type = el.attrsMap.type
131131

132132
// warn if v-bind:value conflicts with v-model
133+
// except for inputs with v-bind:type
133134
if (process.env.NODE_ENV !== 'production') {
134135
const value = el.attrsMap['v-bind:value'] || el.attrsMap[':value']
135-
if (value) {
136+
const typeBinding = el.attrsMap['v-bind:type'] || el.attrsMap[':type']
137+
if (value && !typeBinding) {
136138
const binding = el.attrsMap['v-bind:value'] ? 'v-bind:value' : ':value'
137139
warn(
138140
`${binding}="${value}" conflicts with v-model on the same element ` +

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

+11
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,17 @@ describe('Directive v-model text', () => {
289289
expect('conflicts with v-model').not.toHaveBeenWarned()
290290
})
291291

292+
it('should not warn on input with dynamic type binding', () => {
293+
new Vue({
294+
data: {
295+
type: 'checkbox',
296+
test: 'foo'
297+
},
298+
template: '<input :type="type" v-model="test" :value="test">'
299+
}).$mount()
300+
expect('conflicts with v-model').not.toHaveBeenWarned()
301+
})
302+
292303
if (!isAndroid) {
293304
it('does not trigger extra input events with single compositionend', () => {
294305
const spy = jasmine.createSpy()

0 commit comments

Comments
 (0)