Просмотр исходного кода

only warn v-repeat on options when select has a v-model

Evan You 10 лет назад
Родитель
Сommit
9942ace3ec
2 измененных файлов с 22 добавлено и 14 удалено
  1. 7 1
      src/directives/model/index.js
  2. 15 13
      src/directives/repeat.js

+ 7 - 1
src/directives/model/index.js

@@ -50,9 +50,10 @@ module.exports = {
       )
       )
       return
       return
     }
     }
+    el.__v_model = this
     handler.bind.call(this)
     handler.bind.call(this)
     this.update = handler.update
     this.update = handler.update
-    this.unbind = handler.unbind
+    this._unbind = handler.unbind
   },
   },
 
 
   /**
   /**
@@ -72,5 +73,10 @@ module.exports = {
         this.hasWrite = true
         this.hasWrite = true
       }
       }
     }
     }
+  },
+
+  unbind: function () {
+    this.el.__v_model = null
+    this._unbind && this._unbind()
   }
   }
 }
 }

+ 15 - 13
src/directives/repeat.js

@@ -21,6 +21,21 @@ module.exports = {
    */
    */
 
 
   bind: function () {
   bind: function () {
+
+    // some helpful tips...
+    /* istanbul ignore if */
+    if (
+      process.env.NODE_ENV !== 'production' &&
+      this.el.tagName === 'OPTION' &&
+      this.el.parentNode && this.el.parentNode.__v_model
+    ) {
+      _.warn(
+        'Don\'t use v-repeat for v-model options; ' +
+        'use the `options` param instead: ' +
+        'http://vuejs.org/guide/forms.html#Dynamic_Select_Options'
+      )
+    }
+
     // support for item in array syntax
     // support for item in array syntax
     var inMatch = this.expression.match(/(.*) in (.*)/)
     var inMatch = this.expression.match(/(.*) in (.*)/)
     if (inMatch) {
     if (inMatch) {
@@ -59,19 +74,6 @@ module.exports = {
 
 
     // create cache object
     // create cache object
     this.cache = Object.create(null)
     this.cache = Object.create(null)
-
-    // some helpful tips...
-    /* istanbul ignore if */
-    if (
-      process.env.NODE_ENV !== 'production' &&
-      this.el.tagName === 'OPTION'
-    ) {
-      _.warn(
-        'Don\'t use v-repeat for v-model options; ' +
-        'use the `options` param instead: ' +
-        'http://vuejs.org/guide/forms.html#Dynamic_Select_Options'
-      )
-    }
   },
   },
 
 
   /**
   /**