vue.js - 在运行时更改 Vuetify 2 中主题的主要文本颜色

标签 vue.js frontend vuetify.js

我允许用户通过调用以下命令使用任何十六进制颜色来更改应用程序的主要原色:

changeTheme(color){
  Vuetify.framework.theme.themes.light.primary = color
}

问题是如果选择的颜色太亮或太暗,文本颜色就无法阅读。

enter image description here 有这样的东西吗? ==>

changeTheme(color, textColor){
  Vuetify.framework.theme.themes.light.primary = color <== This line works
  Vuetify.framework.theme.themes.light.primaryText = textColor <== This not
}

我需要将更改应用到所有使用原色的地方、应用栏、按钮等。我还可以在暗模式和亮模式之间切换,因此我需要确保在模式之间切换时颜色文本不会改变。

最佳答案

我的解决方案

vuetify.js

export default new Vuetify({
  icons: {
    iconfont: 'md'
  },
  theme: {
    // dark: true,
    // theme: { disable: true },
    options: { customProperties: true },//add this
    themes: {
      light: {
        primary2: colors.indigo.base,//add this 
        primary2Text: colors.shades.white//You can also use localStorage.getItem('XXX')
      },
      dark: {
        // primary: colors.blue.lighten3,
        background: colors.grey.base
      }
    }
  }
});

视觉

<v-app-bar app class="appbar"></v-app-bar>
.appbar,
.footer {
  background-color: var(--v-primary2-base) !important;
  color: var(--v-primary2Text-base) !important;
}

关于vue.js - 在运行时更改 Vuetify 2 中主题的主要文本颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58356631/

相关文章:

vue.js - Vuetify - 在 v-list-tile-content 中居中内容

vue.js - vuetify 如何将内容设置为选项卡 v-tabs-items

javascript - 修改数据表 Vuetify 2.0 中的默认槽 isOpen

javascript - 如何在 Vue Js 中将数据值从一个组件更改为另一个组件?

javascript - 即使使用单引号,ng-include 也不起作用

php - 将数据打印到外部 JavaScript 文件的更好方法

javafx:make stage 打印另一种方法

javascript - 如何在单击按钮时使用不同的 v-model 在运行时生成嵌套文本框

javascript - IntelliJ 不允许使用 Vue.js 组件模板换行

javascript - Angular2 或 React 或任何其他