7 Ways to write better V-FOR LOOPS

preview_player
Показать описание
Vue v-for loops are something that every project will use at some point or another. They allow you to write for loops in your Vue template code.

In this article, we’ll be covering some amazing ways to make your v-for code more precise, predictable, and efficient.

Think I missed some tips? Let me know in the comments down below your favorite v-for tricks!

CHAPTERS
0:00 Introduction
0:38 ALWAYS use a :key with v-for
1:09 Looping over a range with v-for
1:26 Avoid using v-if with v-for
2:09 Use computed or a method to filter your array
2:36 Use wrapper elements to conditionally render a whole list
3:00 Accessing the index in a v-for loop
3:22 How to Iterate Over an Object
3:58 Final thoughts

FREE VUE 3 CHEATSHEET WITH ESSENTIAL CODE SNIPPETS

follow me on twitter:

INTRO
Daily (Prod. by Lukrembo)

#Vue #VueJS #vfor
Рекомендации по теме
Комментарии
Автор

Iterating over object with "name in in object" it's super awesome 👍. I ve never seen this before

asrorbekmannonov
Автор

great content. But what I miss in this is a 8th tip. Let de API do the hard work. Filtering and such is best done (when having lots of data) to a server. It can utilize caching and such.

jsomhorst
Автор

Your videos are incredibly consice and to the point. Liked and subscribed

QINISO-ZN
Автор

Whole v-for just in few clicks:
I perfer assign key to index, when I am surtan that list length not gonna change.
For that purpose I have shortcut even in Webstorm: f + tab ==> v-for="($item$, index) in $data$" :key="index"
(this f + tab shorthand configured to work ONLY in vue template and ONLY in the tags)
$data$ and $item$ - just places to navigate with tab after snippet was unwrapped.

LuckyStilet
Автор

There is one point that creator missed.
In vue3.x V-IF has Higher precedence as compared to V-FOR

demogyani
Автор

I want to know how to do a range loop in reverse order. For example, from 10 to 1.

devilfriend
Автор

You must learn regexp one time and don't use useless libraries

nnz