Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$vuetify is not present in context #47

Closed
eliyas5044 opened this issue Jul 14, 2019 · 8 comments
Closed

$vuetify is not present in context #47

eliyas5044 opened this issue Jul 14, 2019 · 8 comments

Comments

@eliyas5044
Copy link

Thanks for your great work. $vuetify is not present in nuxt context. if we try to see in mounted hook, it's working

mounted() {
    console.log(this.$vuetify);
}

if we want to see in plugin, $vuetify is undefined

export default function({$vuetify}) {
  console.log($vuetify);
}

or

export default function({app}) {
  console.log(app.$vuetify);
}

if we check all context, $vuetify is not there

export default function(cxt) {
  console.log(cxt);
}
@mgreengithelps
Copy link

Could be wrong, but it should not be available in plugins, per Nuxt Plugin page:

Nuxt.js allows you to define JavaScript plugins to be run before instantiating the root Vue.js Application. This is especially helpful when using your own libraries or external modules.

So if the Vue app is not instantiated yet, then I would suspect you would not be able to access $vuetify within any plugins.

@eliyas5044
Copy link
Author

@mgreengithelps acctullay they forgot to add it in plugin for branch master. Please check these two plugin file. Lastet Plugin, Master branch plugin

@gotenxds
Copy link

+1 I struggled with this for 5 hours yesterday, thought I was the bug...

@kevinmarrec
Copy link
Member

@eliyas5044 Is there any use case to use it in a plugin ? Please let me know, I'll do my best to make it accessible from context in both versions of the module (master / next)

Indeed for now it should be accessible from context only on next version through ctx.app.$vuetify.

@eliyas5044
Copy link
Author

@kevinmarrec sorry for late reply. This is necessary in context menu, if we want to localize vuetify. please check my use case. I used nuxt/i18n for my localization. Now i want to change vuetify local when i18n change.

plugins/i18n.js

export default function({ app }) {
  // onLanguageSwitched called right after a new locale has been set
  app.i18n.onLanguageSwitched = (oldLocale, newLocale) => {
    app.$vuetify.lang.current = newLocale;
  };
}

or

export default function({ $vuetify}) {
  // onLanguageSwitched called right after a new locale has been set
  app.i18n.onLanguageSwitched = (oldLocale, newLocale) => {
    $vuetify.lang.current = newLocale;
  };
}

Thanks

@kevinmarrec
Copy link
Member

kevinmarrec commented Jul 22, 2019

@eliyas5044 Alright I see, seems common use case, will fix that on both branches and will release new version soon

EDIT: It will be a bit tricky for Vuetify 1.5 as it's the Vuetify plugin that installs $vuetify and not Nuxt itself, but should still be achievable.

EDIT2: Well for 2.0.0-beta.x it seems to be aswell Vuetify that registers $vuetify too, it assumes that app.vuetify (Vue options) is defined (which Nuxt module does).

In both versions, It seems $vuetify is a little different, i'm afraid that we can't really bind it to context correctly

@kevinmarrec
Copy link
Member

kevinmarrec commented Jul 22, 2019

@eliyas5044 If you're using 1.5, can you try this ?

Create a new plugin that does :

export default (ctx) {
  ctx.$vuetify = Vue.prototype.$vuetify
}

Vue.prototype.$vuetify is set by Vuetify installation (Vue.use(Vuetify))

or you can also even directly try :

export default function({ app }) {
  // onLanguageSwitched called right after a new locale has been set
  app.i18n.onLanguageSwitched = (oldLocale, newLocale) => {
    app.vuetify.lang.current = newLocale;
  };
}

app.$vuetify does not exist but app.vuetify does.

@tincho425
Copy link

tincho425 commented Jul 1, 2020

I've tried doing:
app.vuetify.framework.theme.themes.light.primary = obj
or
app.context.$vuetify.theme.themes.light.primary = obj
in /plugins/combined-inject.js. And calling the injected method in asyncData by
context.app.$colorsChangeVuetify({"base":"#FFA000","lighten1":"#6A1B9A"})

In other words: I'm trying to update Vuetify's light theme in asyncData.

But the color is not being updated in the Vuetify theme configuration. What I'm doing wrong? Thanks in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants