为 vuetify 组件添加颜色

Posted

技术标签:

【中文标题】为 vuetify 组件添加颜色【英文标题】:Add color to vuetify component 【发布时间】:2019-06-16 06:30:44 【问题描述】:

我正在使用 vuetify 扩展面板 ui 组件 (https://vuetifyjs.com/en/components/expansion-panels)。我很确定如何为此添加颜色。如您所见,我一直在尝试将 color="#26c6da" 添加到多个组件但没有成功。

<template>
  <!-- <v-layout align-start > -->

  <!-- <v-layout align-start justify-center row fill-height> -->
  <v-container row fill-height justify-center style="max-width: 1200px" class="mx-auto" color="#26c6da">
    <!-- <v-layout row fill-> -->
            <!-- <v-layout row justify-space-around> -->

      <v-flex  class="mx-auto" color="#26c6da">
        <v-expansion-panel style="max-width: 1200px" class="mx-auto" color="#26c6da" >
          <v-expansion-panel-content v-for="(item,i) in items" :key="i">
            <div slot="header" class="headline font-weight-bold">item.header</div>
            <v-card >
              <v-card-text class="headline font-weight-bold">item.text</v-card-text>
            </v-card>
          </v-expansion-panel-content>
        </v-expansion-panel>
      </v-flex>
    <!-- </v-layout> -->
  </v-container>

这是一个组件codepen链接:

https://codepen.io/anon/pen/OdJKqm?&editable=true&editors=101

我怎样才能让它工作?

【问题讨论】:

style="color: ..."style="background-color: ..."。道具color="..." 期望these values 之一 一些组件如v-flex 没有color 属性。因此,您必须在主题中设置自定义颜色并使用相关类,或者手动设置样式。 @Traxo 我希望你在设置自定义颜色上放了一个链接。不过还是谢谢你的回答,很有帮助 【参考方案1】:

尝试将style="background:#26c6da;color:white" 之类的标准样式添加到您想要的任何元素:

new Vue(
  el: '#app',

)
<script src="https://cdn.jsdelivr.net/npm/babel-polyfill/dist/polyfill.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vuetify@1.4.0/dist/vuetify.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900|Material+Icons">
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/vuetify@1.4.0/dist/vuetify.min.css">
<div id="app">
  <v-app id="inspire">
    <v-expansion-panel>
      <v-expansion-panel-content v-for="(item,i) in 5" :key="i" style="background:#26c6da;color:white">
        <div slot="header">Item</div>
        <v-card>
          <v-card-text>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</v-card-text>
        </v-card>
      </v-expansion-panel-content>
    </v-expansion-panel>
  </v-app>
</div>

【讨论】:

谢谢,知道如何将文本变成白色而不是黑色吗? 不客气,请参阅我关于更改文本颜色的更新答案

以上是关于为 vuetify 组件添加颜色的主要内容,如果未能解决你的问题,请参考以下文章

当主题更改 vuetify 时,使用“辅助”组件的颜色不会改变

如何在独立/CDN 模式下更改 Vuetify 中的主题颜色?

如何在不更改颜色的情况下禁用 Vuetify 按钮

Vue 3 - Vuetify 3:颜色——文本不起作用

如何更改 Vuetify 中数据表的背景颜色?

如何将 vuetify 添加到默认 vuepress 主题