【发布时间】:2021-09-19 22:03:58
【问题描述】:
我有一部分结构:
....
<template v-for="(item, INDEX) in someList">
<template v-if="thisIsArrayList(item)">
<template v-for="(_item) in item">
<Component
:item="_item"
:key="_item.id"
:myprop="checkIndex(INDEX)" - makes here some manipulation with prev and current INDEX and return iterration++ 0, 1
></Component>
</template>
</template>
<template v-else>
....
</template>
</template>
....
INDEX 可以多次使用相同的值,例如 (22, 22, 22) 下一步,例如 (25, 25) 等等.. 所以我尝试在 props:arrayId 中将 prevINDEX 与 currentIndex 进行比较,以便通过迭代++ 将其传递给子项,就像新值一样
例如:
INDEX 几次等于 22 --> 将其更改为 0 并返回此值 --> 下一个 INDEX 夫妇时间等于 55 --> 将其更改为 1 并返回此值 --> 依此类推...
如何在 Vue 中做到这一点? 或者也许这个逻辑有另一种解决方案?
谢谢。
【问题讨论】:
-
你的问题有点不清楚; the index
v-forparameter 有帮助吗?例如。v-for="(item, index) in items"将使循环中的模板访问索引值,您可以使用它来访问items中的上一个和/或下一个值。 -
我编辑了这个例子..所以你可以看到我的意思是什么 INDEX
标签: javascript vue.js vue-component v-for vue-props