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

Mounted user roles when logged in #15

Closed gladtoseeuhappy closed 4 years ago

gladtoseeuhappy commented 4 years ago

Hello, @williamcruzme, is there a way to mounted Roles and Permission when logged In??

created() {
    async() => {
        const { data: permissions } = await this.$axios.get("/api/auth/permissions");
        const { data: roles } = await this.$axios.get("/api/auth/roles");

        this.$laravel.setPermissions(permissions);
        this.$laravel.setRoles(roles);
        console.log(permissions)
    }
}

I tried above code, but nothing happend in console.log

Thanks..

williamcruzme commented 4 years ago

Hello @N0SYS73M1SS4F3, you could try with:

async created() {
  const { data: permissions } = await this.$axios.get("/api/auth/permissions");
  const { data: roles } = await this.$axios.get("/api/auth/roles");

  this.$laravel.setPermissions(permissions);
  this.$laravel.setRoles(roles);
  console.log(permissions)
}
gladtoseeuhappy commented 4 years ago

Hello @williamcruzme yes, i tried ur code, it work, Roles mounted, Permissions mounted,

but i try bind permission to User to See Sidebar base On Roles by implement like this

in My template

    <div v-for="(item, i) in menus" :key="i" router exact>
    <div v-if="$laravel.hasPermission(item.permission)">
        <template v-if="!item.children">
            <v-list-item :key="i" :to="item.to">
                <v-list-item-content>
                    <v-list-item-title>
                        <v-icon left>{{ item.icon }}</v-icon>
                        {{ item.name }}
                    </v-list-item-title>
                </v-list-item-content>
            </v-list-item>
        </template>

in my Githubissues.

  • Githubissues is a development platform for aggregating issues.