Bläddra i källkod

fix #613 v-repeat object fail on multiple invocations

Evan You 11 år sedan
förälder
incheckning
0a769b9db6
2 ändrade filer med 9 tillägg och 5 borttagningar
  1. 7 4
      src/directive.js
  2. 2 1
      src/directives/repeat.js

+ 7 - 4
src/directive.js

@@ -67,9 +67,6 @@ p._bind = function (def) {
     (!this.isLiteral || this._isDynamicLiteral) &&
     !this._checkStatement()
   ) {
-    // use raw expression as identifier because filters
-    // make them different watchers
-    var watcher = this.vm._watchers[this.raw]
     // wrapped updater for context
     var dir = this
     var update = this._update = function (val, oldVal) {
@@ -77,7 +74,13 @@ p._bind = function (def) {
         dir.update(val, oldVal)
       }
     }
-    if (!watcher) {
+    // use raw expression as identifier because filters
+    // make them different watchers
+    var watcher = this.vm._watchers[this.raw]
+    // v-repeat always creates a new watcher because it has
+    // a special filter that's bound to its directive
+    // instance.
+    if (!watcher || this.name === 'repeat') {
       watcher = this.vm._watchers[this.raw] = new Watcher(
         this.vm,
         this._watcherExp,

+ 2 - 1
src/directives/repeat.js

@@ -18,7 +18,8 @@ module.exports = {
     // uid as a cache identifier
     this.id = '__v_repeat_' + (++uid)
     // we need to insert the objToArray converter
-    // as the first read filter.
+    // as the first read filter, because it has to be invoked
+    // before any user filters. (can't do it in `update`)
     if (!this.filters) {
       this.filters = {}
     }