Why v-if and v-for of vue are not recommended to be used together
When making if
judgments, v-for
it is better v-if
to judge first
Final conclusion: v-for
the priority ratio v-if
is high
in conclusion
- Never use
v-if
andv-for
on the same element at the same time, resulting in a waste of performance (each rendering will first loop and then perform conditional judgment) - To avoid this situation, nest in the outer layer
template
(page rendering does not generatedom
nodes), perform v-if judgment at this layer, and then perform v-for loop inside
<template v-if="isShow">
<p v-for="item in items">
</template>