首页 > 解决方案 > Vuex 商店参考 Vuetify -“TypeError:无法读取未定义的属性‘主题’”

问题描述

我想从 vuex 商店更改 vuetify 的道具。从我可以做的一个组件this.$vuetify.theme.dark = true;。这在商店中是不可能的,但不幸的是,我在尝试时遇到了同样的错误Vue.prototype.$vuetify.theme.dark = true;

我得到的错误是Error in v-on handler: "TypeError: Cannot read property 'theme' of undefined".

在我的 main.js 中,我有以下内容:

Vue.use(Vuetify);
const vuetify = new Vuetify({
  theme: {
    dark: true,
    themes: {
      light: {
        primary: colors.purple,
        secondary: colors.grey.darken1,
        accent: colors.shades.black,
        error: colors.red.accent3,
        background: colors.indigo.lighten5, // Added variable
      },
      dark: {
        primary: colors.blue.lighten3,
        // If using base color, be use to mark as such to get HEX value
        background: colors.indigo.base,
      },
    },
  },
});

new Vue({
  router,
  store,
  vuetify,
  render: (h) => h(App),
}).$mount('#app');

我发现 $vuetify 未定义很奇怪,因为我尝试了类似的东西Vue.prototype.$socket.emit('my_event', { data: 'I\'m connected!' });并且这有效。

这里可能是什么错误?

标签: vue.jsvuexvuetify.js

解决方案


推荐阅读