vue.js - Vue v-row 和 v-col 条件渲染问题
问题描述
所以我有一个看起来像这样的 vuetify 模板
<v-row>
<v-col cols="1"> Text </v-col>
<v-col cols="1" v-if="condition"> .. </v-col>
<v-col cols="1" v-if="condition"> .. </v-col>
<v-col cols="1" v-if="!condition"> .. </v-col>
<v-col cols="1" v-if="!condition"> .. </v-col>
<v-col cols="1" v-if="!condition"> .. </v-col>
</v-row>
所以我的问题是,不是向我所有的 v-cols 添加 v-if,有没有办法对它们进行分组,我尝试了以下方法:
<v-row>
<v-col cols="1"> Text </v-col>
<div v-if="condition>
<v-col cols="1"> .. </v-col>
<v-col cols="1"> .. </v-col>
</div>
<div v-if="!condition>
<v-col cols="1"> .. </v-col>
<v-col cols="1"> .. </v-col>
<v-col cols="1"> .. </v-col>
</div>
</v-row>
但是 div 标签会改变 UI 并垂直显示 v-col 是否有我可以使用的标签
解决方案
为此,您可以template
像这样简单地使用良好的 'ole 标签:
<template v-if="condition>
<v-col cols="1"> .. </v-col>
<v-col cols="1"> .. </v-col>
</template>
<template v-if="!condition>
<v-col cols="1"> .. </v-col>
<v-col cols="1"> .. </v-col>
<v-col cols="1"> .. </v-col>
</template>
推荐阅读
- javascript - 使用 localstorage 和 jquery 刷新页面后保持用户登录的问题
- firebase - Firestore 在颤动中订购了集合
- javascript - 如何使用 vuejs 删除小数点
- build - 如何构建 electron-v9.2 的调试版本?
- c++ - Qt5 未定义对 vtable CMake 构建问题的引用
- c++ - ld:在 Makefile 中使用 -static-libstdc++ 时无法识别 -a 选项“tic-libstdc++”?
- java - Java程序退出/终止时如何在内部检测
- java - 针对高 CPU/内存工作负载优化 Spring Boot 后端
- java - javafaker - 由于错误无法生成英国邮政编码
- python - 在 VS Code 终端中运行 Python