Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing $vuetify instance property from vuex store

I was using vuetify and wanted to change theme from vuex store using $vuetify instance but i got this error Cannot set property 'theme' of undefined"

here is my code

export default {
  getters: {},
  mutations: {
    toggleDarkTheme(state) {
      this.$vuetify.theme.primary = "#424242";
    }
  }
};
like image 540
ShegaMike Avatar asked Jun 29 '18 17:06

ShegaMike


3 Answers

$vuetify is an instance property hence you can access any vue instance property using

Vue.prototype.$prop

For your case

import Vue from 'vue';
export default {
  getters: {},
  mutations: {
    toggleDarkTheme(state) {
      Vue.prototype.$vuetify.theme.primary = "#424242";
    }
  }
};
like image 133
Mehari Mamo Avatar answered Nov 19 '22 05:11

Mehari Mamo


For Vuetify 2.0 you can try following method. (After following Vuetify 2.0 Upgrade guide for themes)

import Vuetify from './plugins/vuetify'

export default {
  getters: {},
  mutations: {
    toggleDarkTheme(state) {
      Vuetify.framework.theme.themes.light.primary = "#424242";
    }
  }
like image 13
Samiullah Khan Avatar answered Nov 19 '22 06:11

Samiullah Khan


This one worked for me

...
toggleDarkTheme(state) {
   window.$nuxt.$root.$vuetify.theme.dark = true
}
like image 8
Temo Avatar answered Nov 19 '22 06:11

Temo