【问题标题】:get user permissions with laravel vue rest api使用 laravel vue rest api 获取用户权限
【发布时间】:2020-12-27 15:40:32
【问题描述】:

我正在尝试使用 Laravel 为后端和 vuejs 为前端获取所有用户权限。 我怎样才能从 api 到 vue?什么是最好的选择? 我尝试使用以下代码获取它们,但显示错误

在permissionMixin中:

import PermissionDataService from '../../Servieces/PermissionDataService'

export default {

    methods: {
        checkPermission() {
            let permissions;
            PermissionDataService.get("user_permissions")
                .then((response) => {
                    permissions= response.data;
                })
                .catch((error) => {
                    console.debug(error)
                });
            return hasAccess;
        }
    }
}

这就是我在 main.js 中使用它的方式:

import permission from "@/core/mixins/permissionMixin";
Vue.mixin(permission);
window.Laravel = this.checkPermission();

console.debug(Laravel)

Vue.directive('can', function (el, binding) {
    return Laravel.permissions.indexOf(binding) !== -1;
});

但总是向我显示此错误:

Uncaught TypeError: can't access property "defaults", a.default.axios is undefined

我完全确定端点没问题 有什么想法吗?

【问题讨论】:

    标签: laravel vue.js permissions roles laravel-permission


    【解决方案1】:

    终于解决了。 我不得不放

    window.Laravel = this.checkPermission();
    

    进入布局文件之一

    【讨论】:

      猜你喜欢
      • 2016-06-02
      • 1970-01-01
      • 1970-01-01
      • 2022-01-22
      • 2014-06-23
      • 2021-05-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-29
      相关资源
      最近更新 更多