Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v-for多层嵌套,当外层循环和内层循环的 :key 重名时,会导致 f_` 取到错误的值的情况。 #298

Open
dujuncheng opened this issue Oct 8, 2019 · 0 comments

Comments

@dujuncheng
Copy link

使用 megalo 写的v-for多层嵌套,当外层循环和内层循环的 :key 重名时,会导致 f_ 取到错误的值的情况,从而导致展示的数据有误。

出错的代码片段:

<view v-for="(item, index) in list" :key="index">
  <view v-for="(goods, index) in  item.list" :key="index"></view>
</view>

上面的代码vue打包为h5是 ok的,但是打包为微信小程序则数据出错。
看了一下megalo的源码,

上面代码中,对比右左侧的 render 函数, 两个 index 都是外层循环的索引,�导致在运行时 getHid 方法中, 错误的计算了 f_ 值为 外层循环的index- 外层循环的index , 然后app内维护的数据就变成了

{
$root: {
   0: {
      h: { 
         3-0-0
         3-1-1
         3-2-2
         3-3-3
    }
   }
  }
}

而期望的数据应该是:


$root: {
   0: {
      h: { 
         3-0-0
         3-0-1
         3-0-2
         3-0-3
        ……
    }
   }
  }
}

辛苦维护者 fix 一下

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant