关于vue admin element的权限

router/index

export const constantRoutes = [
 // ... 
 {
    path: '/',
    component: Layout,
    redirect: '/company/index'
  }
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
  // 项目的路由开始
  {
    path: '/company',
    component: Layout,
    redirect: '/company/index',
    name: 'Company',
    meta: {
      title: '入驻页',
      icon: 'guide',
      roles: ['editor']
    },
    alwaysShow: false,
    children: [
      {
        path: 'index',
        component: () => import('@/views/company/index'),
        name: 'CompanyIndex',
        meta: { title: '欢迎页', icon: 'guide', noCache: true }
      },
      {
        path: 'base',
        component: () => import('@/views/company/base'),
        name: 'CompanyBase',
        hidden: true,
        meta: { title: '表单页', icon: 'guide', noCache: false, keepAlive: true } // , roles: ['editor']
      },
      {
        path: 'person',
        component: () => import('@/views/company/person'),
        name: 'CompanyPerson',
        hidden: true,
        meta: { title: '自然人页', icon: 'guide', noCache: true }
      },
      {
        path: 'enterprise',
        component: () => import('@/views/company/enterprise'),
        name: 'CompanyEnterprise',
        hidden: true,
        meta: { title: '非自然人页', icon: 'guide', noCache: true }
      }
    ]
  },
  // ....

这个配置写的有毛病吗?为啥meta中一加roles角色设置都无法登陆。提示

TypeError: roles.some is not a function

以下是服务器端的响应

我只是将mock/user下的代码移到服务器上了

阅读 1.9k
1 个回答

返回的数据里roles这个格式不对吧,应该是这样:

{
    "roles": ["editor"]
}

是一个数组,但你返回的是"['editor']",返回了个字符串

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题