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

warning against binding to primitive values

Evan You 10 лет назад
Родитель
Сommit
66d1f336ed
2 измененных файлов с 15 добавлено и 1 удалено
  1. 6 1
      src/directives/for.js
  2. 9 0
      src/watcher.js

+ 6 - 1
src/directives/for.js

@@ -1,9 +1,10 @@
 var _ = require('../util')
+var config = require('../config')
 var FragmentFactory = require('../fragment/factory')
 var isObject = _.isObject
 var uid = 0
 
-// TODO: ref, el, primitive v-model sync.
+// TODO: ref, el
 
 module.exports = {
 
@@ -34,6 +35,9 @@ module.exports = {
     // check for trackby param
     this.idKey = this._checkParam('track-by')
 
+    // check v-ref
+    this.refId = this._checkParam(config.prefix + 'ref')
+
     // check for transition stagger
     var stagger = +this._checkParam('stagger')
     this.enterStagger = +this._checkParam('enter-stagger') || stagger
@@ -53,6 +57,7 @@ module.exports = {
     var scope = Object.create(parentScope)
     // make sure point $parent to parent scope
     scope.$parent = parentScope
+    scope.$alias = alias
     // define scope properties
     _.defineReactive(scope, alias, value)
     _.defineReactive(scope, '$index', index)

+ 9 - 0
src/watcher.js

@@ -144,6 +144,15 @@ Watcher.prototype.set = function (value) {
       )
     }
   }
+  if (process.env.NODE_ENV !== 'production' &&
+      scope.$alias === this.expression) {
+    _.warn(
+      'It seems you are using two-way binding on a v-for ' +
+      'alias. This will not affect the original array. ' +
+      'Use an array of objects and bind to an object ' +
+      'property instead.'
+    )
+  }
 }
 
 /**