Skip to content

Can I use the next value in advance in v-for? #2621

Closed Answered by flaghrbs1004
flaghrbs1004 asked this question in Q&A
Discussion options

You must be logged in to vote

{{ 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 : '' }}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by flaghrbs1004
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant