vue.js - 在 vuetify 2.x 中显示突出显示的列表项
问题描述
我正在用 vuetify 2.x 编写我的第一个应用程序。该应用程序正在显示一个项目列表,这些项目是具有文本 ( item.t
) 字符串字段和选中 ( item.c
) 布尔字段的对象。
我想以当前主题颜色显示选中的项目,并以相反的主题颜色(突出显示)显示未选中的项目。因此,它取决于item.c
字段值的值。
我假设更改列表项的它们会反转其内容的颜色。黑色 <-> 白色。
我怎么能那样做?
这是我的列表组件:
<template>
<v-list dense>
<template v-for="(item, index) in items">
<v-list-item :key="item.r">
<v-list-item-content class="font-weight-medium">
<v-layout>
<v-row align="center">
<v-col cols="2">
<v-row no-gutters justify="end">
{{ item.n }}
</v-row>
</v-col>
<v-col cols="10" class="px-0">
<v-row no-gutters>{{ item.t }}</v-row>
</v-col>
</v-row>
</v-layout>
</v-list-item-content>
</v-list-item>
<v-divider
v-if="index < items.length - 1"
:key="`divider-${index}`"
></v-divider>
</template>
</v-list>
</template>
<script>
export default {
name: "itemList",
computed: {
items() {
return this.$store.getters.currentListItems;
},
},
};
</script>
我尝试了很多事情都没有成功,但找不到如何做到这一点的例子。
编辑:由于项目只包含文本而没有图标,也许改变背景和文本颜色就足够了。主题的好处是它还可以反转图标。
解决方案
您可以通过 v-menu 通过 v-select 或 v-combo-box 以不同的方式执行此操作,在这里您可以使用多个选项 https://vuetifyjs.com/en/components/combobox/#dense 但我认为您需要使用组合框,在这里您可以自由思考
推荐阅读
- java - 如何在 Spring Boot 中将属性文件中的 keycloak 配置与 WebSecurity 类一起使用
- r - Xpath 没有在 Rvest 中“看到”表
- linux - Flutter 渲染器启动失败:没有可用的 GL 实现
- nginx - 随机,“open()”/run/nginx.pid“失败(2:没有这样的文件或目录)”发生
- java - spring boot中的@Transactionnal注解真的会创建事务吗?
- c# - 从nodejs net客户端到c#.net服务器的Socket通信
- ruby-on-rails - 如何打印 Rails POST 请求输出?
- clickhouse - Clickhouse 物化视图是否支持来自多个物化视图的填充?
- swift - SwiftUI view animates at unexpected path
- blockchain - 在 1 笔交易中检索 Chainlink VRF 生成的随机数