Browse Source

add v-model dynamic type warning

dev
Evan You 8 years ago
parent
commit
f35f7e35cd
  1. 9
      src/platforms/web/compiler/directives/model.js
  2. 14
      test/unit/features/directives/model-dynamic.spec.js

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

@ -15,6 +15,15 @@ export default function model (
const modifiers = dir.modifiers
const tag = el.tag
const type = el.attrsMap.type
if (process.env.NODE_ENV !== 'production') {
const dynamicType = el.attrsMap['v-bind:type'] || el.attrsMap[':type']
if (tag === 'input' && dynamicType) {
warn(
`<input :type="${dynamicType}" v-model="${value}">:\n` +
`v-model does not support dynamic input types. Use v-if branches instead.`
)
}
}
if (tag === 'select') {
return genSelect(el, value)
} else if (tag === 'input' && type === 'checkbox') {

14
test/unit/features/directives/model-dynamic.spec.js

@ -0,0 +1,14 @@
import Vue from 'vue'
describe('Directive v-model dynamic input type', () => {
it('should warn', function () {
new Vue({
data: {
type: 'text',
text: 'hi'
},
template: `<input :type="type" v-model="text">`
}).$mount()
expect(`v-model does not support dynamic input types`).toHaveBeenWarned()
})
})
Loading…
Cancel
Save