使用 laravel vue rest api 获取用户权限

get user permissions with laravel vue rest api

我正在尝试使用 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

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

终于解决了。 我不得不把

window.Laravel = this.checkPermission();

进入布局文件之一