@@ -249,7 +249,7 @@ module.exports = {
249249 for ( i = 0 , l = data . length ; i < l ; i ++ ) {
250250 obj = data [ i ]
251251 raw = converted ? obj . $value : obj
252- vm = ! init && this . getVm ( raw , converted ? obj . $key : null )
252+ vm = ! init && this . getVm ( raw , i , converted ? obj . $key : null )
253253 if ( vm ) { // reusable instance
254254 vm . _reused = true
255255 vm . $index = i // update $index
@@ -375,7 +375,7 @@ module.exports = {
375375 vm . _repeat = true
376376 // cache instance
377377 if ( needCache ) {
378- this . cacheVm ( raw , vm , this . converted ? meta . $key : null )
378+ this . cacheVm ( raw , vm , index , this . converted ? meta . $key : null )
379379 }
380380 // sync back changes for two-way bindings of primitive values
381381 var type = typeof raw
@@ -427,15 +427,20 @@ module.exports = {
427427 *
428428 * @param {Object } data
429429 * @param {Vue } vm
430+ * @param {Number } index
430431 * @param {String } [key]
431432 */
432433
433- cacheVm : function ( data , vm , key ) {
434+ cacheVm : function ( data , vm , index , key ) {
434435 var idKey = this . idKey
435436 var cache = this . cache
436437 var id
437438 if ( key || idKey ) {
438- id = idKey ? data [ idKey ] : key
439+ var id = idKey
440+ ? idKey === '$index'
441+ ? index
442+ : data [ idKey ]
443+ : key
439444 if ( ! cache [ id ] ) {
440445 cache [ id ] = vm
441446 } else {
@@ -469,14 +474,19 @@ module.exports = {
469474 * Try to get a cached instance from a piece of data.
470475 *
471476 * @param {Object } data
477+ * @param {Number } index
472478 * @param {String } [key]
473479 * @return {Vue|undefined }
474480 */
475481
476- getVm : function ( data , key ) {
482+ getVm : function ( data , index , key ) {
477483 var idKey = this . idKey
478484 if ( key || idKey ) {
479- var id = idKey ? data [ idKey ] : key
485+ var id = idKey
486+ ? idKey === '$index'
487+ ? index
488+ : data [ idKey ]
489+ : key
480490 return this . cache [ id ]
481491 } else if ( isObject ( data ) ) {
482492 return data [ this . id ]
@@ -507,7 +517,11 @@ module.exports = {
507517 var idKey = this . idKey
508518 var convertedKey = vm . $key
509519 if ( idKey || convertedKey ) {
510- var id = idKey ? data [ idKey ] : convertedKey
520+ var id = idKey
521+ ? idKey === '$index'
522+ ? vm . $index
523+ : data [ idKey ]
524+ : convertedKey
511525 this . cache [ id ] = null
512526 } else if ( isObject ( data ) ) {
513527 data [ this . id ] = null
0 commit comments