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
263 stars 31 forks source link

TypeError: Cannot read properties of undefined (reading 'setPermissions') in Nuxt.js #61

Open yudanf93 opened 1 year ago

yudanf93 commented 1 year ago

` const role = this.$store.state.role.roles const user = ['user']

        const roleJson = JSON.stringify(role)
        const userJson = JSON.stringify(user)
        if (roleJson === userJson) {
            this.$gates.setPermissions([
                'view sales',
                'add sales',
                'edit sales',
                'delete sales',
                'import sales',
                'summary report',
                'product report',
                'daily sale report',
                'monthly sale report',
                'daily purchase report',
                'sale report',
                'purchase report',
                'warehouse report',
                'product qty alert',
                'customer report',
                'supplier report',
                'due report',
                'pos'
            ])
            console.log(this.$gates)
        }`

<button v-permission="'add sales'">Add Sales</button>

setting in plugins/vue-gates.js `import Vue from 'vue' import VueGates from 'vue-gates'

Vue.use(VueGates)

export default (_context, inject) => { inject('gates', Vue.prototype.$gates) }`

someone please help me