当前位置:网站首页>Why can't V-IF and V-for be used together
Why can't V-IF and V-for be used together
2022-04-23 05:25:00 【Python User】
v-if and v-for It can't be used together , Otherwise, it will cause a waste of performance !
reason : stay Vue2 in v-for Has a higher priority than v-if, If v-if The value of is false when ,v-for Still render according to priority , This creates a waste of resources , As shown below :
<template>
<div>
<!-- Can't be used at the same time , Waste of resources -->
<div v-for = "(it, i) in getData" v-key="i" v-if="flag">
</div>
</tempalte>
<script> export default {
data(){
return{
getData:[1,2,3], flag: false } } } </script>
Can be v-if Package in the outermost layer to solve :
<template>
<div>
<div v-if="flag">
<div v-for = "(it, i) in getData" v-key="i" ></div>
</div>
<!-- If you don't want to use it div label , You can also use template-->
<template v-if="flag">
<div v-for = "(it, i) in getData" v-key="i" ></div>
</template>
</div>
</tempalte>
<script> export default {
data(){
return{
getData:[1,2,3], flag: false } } } </script>
版权声明
本文为[Python User]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220544545497.html
边栏推荐
猜你喜欢
Blender programmed terrain production
Requirements for SQL server to retrieve SQL and user information
JS Array常见方法
2021-09-28
DevOps生命周期,你想知道的全都在这里了!
Using PHP post temporary file mechanism to upload arbitrary files
Five key technologies to improve the devsecops framework
2021-09-27
[untitled]
selenium預先加載cookie的必要性
随机推荐
phphphphphphphp
The annual transaction volume of the app store is US $1 million, and only 15% commission is paid. Small and medium-sized developers are very contradictory
[untitled] kimpei kdboxpro's cool running lantern coexists with beauty and strength
Low code and no code considerations
Mairadb数据库基本操作之数据管理
2021-11-01
青岛敏捷之旅,来了!
2021-10-12
How to set the initial value of El input number to null
Three of three JS (webgl) is simple to draw lines / arcs according to points (based on linegeometry / line2 / linematerial, draw two arc segments based on the center of the circle)
SQL Server检索SQL和用户信息的需求
Uncle wolf is looking for a translator -- Plato -- ongoing translation
FileReader API file operation
《2021年IT行业项目管理调查报告》重磅发布!
即将毕业的大学生找技术开发工作的焦虑根源
数字化转型失败,有哪些原因?
Master-slave replication of MariaDB database
使用宝塔+xdebug+vscode远程调试代码
egg的static的前缀是可以修改惹,靴靴
4 个最常见的自动化测试挑战及应对措施