Can I use the next value in advance in v-for? #2621
-
I want to compare the current value and the next value together in v-for But if you do that, you will end up with an error. |
Beta Was this translation helpful? Give feedback.
Answered by flaghrbs1004 Dec 22, 2023
Replies: 1 comment
-
{{ items[index+1].message }} When you reach the last item in the loop, an error occurs because you are looking for an undefined object. Just check whether it is the last object or not. {{ items[index+1] ? items[index+1].message : '' }} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by flaghrbs1004
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
{{ items[index+1].message }}
When you reach the last item in the loop, an error occurs because you are looking for an undefined object.
Just check whether it is the last object or not.
{{ items[index+1] ? items[index+1].message : '' }}