代码之家  ›  专栏  ›  技术社区  ›  miqe

从Vuex存储访问$Vuetify实例属性

  •  1
  • miqe  · 技术社区  · 7 年前

    我在用 vuetify 想改变主题 vuex 存储使用 $vuetify 但我犯了个错误 Cannot set property 'theme' of undefined"

    这是我的密码

    export default {
      getters: {},
      mutations: {
        toggleDarkTheme(state) {
          this.$vuetify.theme.primary = "#424242";
        }
      }
    };
    
    1 回复  |  直到 7 年前
        1
  •  5
  •   mehari    7 年前

    $vuetify是 instance property 因此您可以访问任何Vue 实例属性使用

    Vue.prototype.$prop
    

    为了你的案子

    import Vue from 'vue';
    export default {
      getters: {},
      mutations: {
        toggleDarkTheme(state) {
          Vue.prototype.$vuetify.theme.primary = "#424242";
        }
      }
    };
    
        2
  •  3
  •   Samiullah Khan    6 年前

    为了 Vuetify 2.0版 你可以试试下面的方法。 (在遵循Vuetify 2.0之后 Upgrade guide 对于主题)

    import vuetify from './plugins/vuetify'
    
    export default {
      getters: {},
      mutations: {
        toggleDarkTheme(state) {
          Vuetify.framework.theme.themes.light.primary = "#424242";
        }
      }
    
    推荐文章