williamcruzme / vue-gates

🔒 A Vue.js & Nuxt.js plugin that allows you to use roles and permissions in your components or DOM elements, also compatible as middleware and methods.
https://williamcruzme.github.io/vue-gates/
MIT License
264 stars 31 forks source link

dumb question.. using $gates in store? - $gates is undefined #33

Closed baradhili closed 3 years ago

baradhili commented 3 years ago

I've probably just had my brain go to sleep but when trying to use this.$gates.setRoles() in the store (I've fetched user data inc roles and perms and want to load them) I also tried $gates.setRoles() with the same result

I get Uncaught (in promise) TypeError: this.$gates is undefined

I'm new to Vue in general so I've probably done something wrong :)

I do have it in my main.js

import { createApp } from 'vue'
import App from './App.vue'
import { store } from './store/index.js'
import { router }  from './routes/index.js'
import VueGates from 'vue-gates';

const app = createApp(App)
app.use(store)
app.use(router)
app.use(VueGates)
app.mount('#app')
baradhili commented 3 years ago

outside of store I can see $gates, just inside I can't.. this is under vue v3.0.5

Th3Cod3 commented 3 years ago

I solved in this way for other files, but I think it should work

import Vue from "vue";
import VueGates from 'vue-gates'

Vue.use(VueGates, {
    persistent: true
});

const vueGates = Vue.prototype.$gates;

Of maybe test install Vue.use() before your store.