diff --git a/src/compiler/codegen.js b/src/compiler/codegen.js index 79e2e1ce..29fdefc3 100644 --- a/src/compiler/codegen.js +++ b/src/compiler/codegen.js @@ -182,7 +182,7 @@ function genDirectives (el: ASTElement): string | void { if (gen) { // compile-time directive that manipulates AST. // returns true if it also needs a runtime counterpart. - needRuntime = !!gen(el, dir) + needRuntime = !!gen(el, dir, warn) } if (needRuntime) { hasRuntime = true diff --git a/src/platforms/web/compiler/directives/model.js b/src/platforms/web/compiler/directives/model.js index 05f4a51a..4cfd3106 100644 --- a/src/platforms/web/compiler/directives/model.js +++ b/src/platforms/web/compiler/directives/model.js @@ -2,7 +2,11 @@ import { addHandler, addProp, getBindingAttr } from 'compiler/helpers' -export default function model (el: ASTElement, dir: ASTDirective) { +export default function model ( + el: ASTElement, + dir: ASTDirective, + warn: Function +): ?boolean { const value = dir.value const modifiers = dir.modifiers if (el.tag === 'select') { @@ -20,12 +24,12 @@ export default function model (el: ASTElement, dir: ASTDirective) { genRadioModel(el, value) break default: - return genDefaultModel(el, value, modifiers) + return genDefaultModel(el, value, modifiers, warn) } } } -function genCheckboxModel (el, value) { +function genCheckboxModel (el: ASTElement, value: ?string) { const valueBinding = getBindingAttr(el, 'value') addProp(el, 'checked', `Array.isArray(${value})` + @@ -45,13 +49,35 @@ function genCheckboxModel (el, value) { ) } -function genRadioModel (el, value) { +function genRadioModel (el: ASTElement, value: ?string) { const valueBinding = getBindingAttr(el, 'value') addProp(el, 'checked', `(${value}==${valueBinding})`) addHandler(el, 'change', `${value}=${valueBinding}`) } -function genDefaultModel (el, value, modifiers) { +function genDefaultModel ( + el: ASTElement, + value: ?string, + modifiers: ?Object, + warn: Function +): ?boolean { + if (process.env.NODE_ENV !== 'production') { + if (el.tag === 'input' && el.attrsMap.value) { + warn( + `<${el.tag} v-model="${value}" value="${el.attrsMap.value}">:\n` + + 'inline value attributes will be ignored when using v-model. ' + + 'Declare initial values in the component\'s data option instead.' + ) + } + if (el.tag === 'textarea' && el.children.length) { + warn( + `' + }).$mount() + expect(vm.test).toBe('foo') + expect(vm.$el.value).toBe('foo') + expect('inline content inside