Ver código fonte

remove inline value warnings for checkbox/radio/select also (close #5112)

Evan You 9 anos atrás
pai
commit
c619b8d22c

+ 0 - 34
src/platforms/web/compiler/directives/model.js

@@ -70,14 +70,6 @@ function genCheckboxModel (
   value: string,
   modifiers: ?ASTModifiers
 ) {
-  if (process.env.NODE_ENV !== 'production' &&
-    el.attrsMap.checked != null) {
-    warn(
-      `<${el.tag} v-model="${value}" checked>:\n` +
-      `inline checked attributes will be ignored when using v-model. ` +
-      'Declare initial values in the component\'s data option instead.'
-    )
-  }
   const number = modifiers && modifiers.number
   const valueBinding = getBindingAttr(el, 'value') || 'null'
   const trueValueBinding = getBindingAttr(el, 'true-value') || 'true'
@@ -109,14 +101,6 @@ function genRadioModel (
     value: string,
     modifiers: ?ASTModifiers
 ) {
-  if (process.env.NODE_ENV !== 'production' &&
-    el.attrsMap.checked != null) {
-    warn(
-      `<${el.tag} v-model="${value}" checked>:\n` +
-      `inline checked attributes will be ignored when using v-model. ` +
-      'Declare initial values in the component\'s data option instead.'
-    )
-  }
   const number = modifiers && modifiers.number
   let valueBinding = getBindingAttr(el, 'value') || 'null'
   valueBinding = number ? `_n(${valueBinding})` : valueBinding
@@ -129,10 +113,6 @@ function genSelect (
     value: string,
     modifiers: ?ASTModifiers
 ) {
-  if (process.env.NODE_ENV !== 'production') {
-    el.children.some(checkOptionWarning)
-  }
-
   const number = modifiers && modifiers.number
   const selectedVal = `Array.prototype.filter` +
     `.call($event.target.options,function(o){return o.selected})` +
@@ -145,20 +125,6 @@ function genSelect (
   addHandler(el, 'change', code, null, true)
 }
 
-function checkOptionWarning (option: any): boolean {
-  if (option.type === 1 &&
-    option.tag === 'option' &&
-    option.attrsMap.selected != null) {
-    warn(
-      `<select v-model="${option.parent.attrsMap['v-model']}">:\n` +
-      'inline selected attributes on <option> will be ignored when using v-model. ' +
-      'Declare initial values in the component\'s data option instead.'
-    )
-    return true
-  }
-  return false
-}
-
 function genDefaultModel (
   el: ASTElement,
   value: string,

+ 0 - 11
test/unit/features/directives/model-checkbox.spec.js

@@ -256,15 +256,4 @@ describe('Directive v-model checkbox', () => {
       expect(vm.$el.checked).toBe(true)
     }).then(done)
   })
-
-  it('warn inline checked', () => {
-    const vm = new Vue({
-      template: `<input type="checkbox" v-model="test" checked>`,
-      data: {
-        test: false
-      }
-    }).$mount()
-    expect(vm.$el.checked).toBe(false)
-    expect('inline checked attributes will be ignored when using v-model').toHaveBeenWarned()
-  })
 })

+ 0 - 11
test/unit/features/directives/model-radio.spec.js

@@ -251,15 +251,4 @@ describe('Directive v-model radio', () => {
       expect(vm.$el.checked).toBe(false)
     }).then(done)
   })
-
-  it('warn inline checked', () => {
-    const vm = new Vue({
-      template: `<input v-model="test" type="radio" value="1" checked>`,
-      data: {
-        test: '2'
-      }
-    }).$mount()
-    expect(vm.$el.checked).toBe(false)
-    expect('inline checked attributes will be ignored when using v-model').toHaveBeenWarned()
-  })
 })

+ 0 - 15
test/unit/features/directives/model-select.spec.js

@@ -430,21 +430,6 @@ describe('Directive v-model select', () => {
     }).then(done)
   })
 
-  it('should warn inline selected', () => {
-    const vm = new Vue({
-      data: {
-        test: null
-      },
-      template:
-        '<select v-model="test">' +
-          '<option selected>a</option>' +
-        '</select>'
-    }).$mount()
-    expect(vm.$el.selectedIndex).toBe(-1)
-    expect('inline selected attributes on <option> will be ignored when using v-model')
-      .toHaveBeenWarned()
-  })
-
   it('should warn multiple with non-Array value', done => {
     new Vue({
       data: {