Bläddra i källkod

wathcer: improve warning check for two-way bindings for v-for with filters (close #1433)

Evan You 10 år sedan
förälder
incheckning
9af9c29907
1 ändrade filer med 17 tillägg och 8 borttagningar
  1. 17 8
      src/watcher.js

+ 17 - 8
src/watcher.js

@@ -145,17 +145,26 @@ Watcher.prototype.set = function (value) {
   }
   // two-way sync for v-for alias
   var forContext = scope.$forContext
-  if (forContext && forContext.alias === this.expression) {
-    if (forContext.filters) {
-      process.env.NODE_ENV !== 'production' && _.warn(
+  if (process.env.NODE_ENV !== 'production') {
+    if (
+      forContext &&
+      forContext.filters &&
+      (new RegExp(forContext.alias + '\\b')).test(this.expression)
+    ) {
+      _.warn(
         'It seems you are using two-way binding on ' +
-        'a v-for alias, and the v-for has filters. ' +
-        'This will not work properly. Either remove the ' +
-        'filters or use an array of objects and bind to ' +
-        'object properties instead.'
+        'a v-for alias (' + this.expression + '), and the ' +
+        'v-for has filters. This will not work properly. ' +
+        'Either remove the filters or use an array of ' +
+        'objects and bind to object properties instead.'
       )
-      return
     }
+  }
+  if (
+    forContext &&
+    forContext.alias === this.expression &&
+    !forContext.filters
+  ) {
     if (scope.$key) { // original is an object
       forContext.rawValue[scope.$key] = value
     } else {