1

我需要访问嵌套 v-for 循环的索引变量。这可以做到吗?我的代码是

<div v-for="(dayDataArray, key, index) in props_league_data_nfl">
     <div v-for="(arrayItem, key, arrayItemIndex) in dayDataArray" class="col-xs-12 col-sm-4 col-lg-3">



    <!-- some code here -->

<div> {{ props_box_game_scores_nfl[nfl_days[index].split(' ')[0].toLowerCase()][arrayItemIndex] }} </div>`

如果我像上面那样为索引设置单独的名称,那么arrayItemIndex似乎被忽略了。如果我对两个 for 循环都使用index ,那么我会在nfl_days[index]参考中得到一个异常。如何访问第二个索引变量?似乎在这两种情况下都必须使用索引名称?任何建议或解决方法表示赞赏...

4

1 回答 1

1

因为一个数组v-for只有两个参数,而不是三个。所以应该是:

v-for="(arrayItem, arrayItemIndex) in dayDataArray"

迭代对象时,它只有 3 个参数。

于 2019-10-02T18:14:27.083 回答