// dev/src/platforms/web/compiler/directives/model.js line 14 exportdefaultfunctionmodel ( el: ASTElement, dir: ASTDirective, _warn: Function ): ?boolean { warn = _warn const value = dir.value const modifiers = dir.modifiers const tag = el.tag const type = el.attrsMap.type
if (process.env.NODE_ENV !== 'production') { // inputs with type="file" are read only and setting the input's // value will throw an error. if (tag === 'input' && type === 'file') { warn( `<${el.tag} v-model="${value}" type="file">:\n` + `File inputs are read only. Use a v-on:change listener instead.`, el.rawAttrsMap['v-model'] ) } } // 分支处理 if (el.component) { genComponentModel(el, value, modifiers) // component v-model doesn't need extra runtime returnfalse } elseif (tag === 'select') { genSelect(el, value, modifiers) } elseif (tag === 'input' && type === 'checkbox') { genCheckboxModel(el, value, modifiers) } elseif (tag === 'input' && type === 'radio') { genRadioModel(el, value, modifiers) } elseif (tag === 'input' || tag === 'textarea') { genDefaultModel(el, value, modifiers) } elseif (!config.isReservedTag(tag)) { genComponentModel(el, value, modifiers) // component v-model doesn't need extra runtime returnfalse } elseif (process.env.NODE_ENV !== 'production') { warn( `<${el.tag} v-model="${value}">: ` + `v-model is not supported on this element type. ` + 'If you are working with contenteditable, it\'s recommended to ' + 'wrap a library dedicated for that purpose inside a custom component.', el.rawAttrsMap['v-model'] ) }
// dev/src/platforms/web/compiler/directives/model.js line 127 functiongenDefaultModel ( el: ASTElement, value: string, modifiers: ?ASTModifiers ): ?boolean { const type = el.attrsMap.type
// warn if v-bind:value conflicts with v-model // except for inputs with v-bind:type // value与v-model冲突则发出警告 if (process.env.NODE_ENV !== 'production') { const value = el.attrsMap['v-bind:value'] || el.attrsMap[':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 ` + 'because the latter already expands to a value binding internally', el.rawAttrsMap[binding] ) } }