Browse Source

fix v-for object repeat track-by="$index"

Evan You 10 years ago
parent
commit
984f82c058
1 changed files with 6 additions and 1 deletions
  1. 6 1
      src/directives/for.js

+ 6 - 1
src/directives/for.js

@@ -83,7 +83,12 @@ module.exports = {
       frag = !init && this.getCachedFrag(value, i, key)
       if (frag) { // reusable fragment
         frag.reused = true
-        frag.scope.$index = i // update $index
+        // update $index
+        frag.scope.$index = i
+        // update $key
+        if (key) {
+          frag.scope.$key = key
+        }
         // update data for track-by, object repeat &
         // primitive values.
         if (idKey || converted || primitive) {