iview-admin中如何用接口获取到的菜单数据去写到routers.js中

export const loginRouter= {

path: '#login',
name: 'login',
meta: {
  title: 'Login - 登录',
  hideInMenu: true
},
component: () => import('@/view/login/login.vue')

};

export const indexRouter = {

path: '/',
name: '_home',
redirect: '/home',
component: Main,
meta: {
  hideInMenu: true,
  notCache: true
},

children: [
  {
    path: 'home',
    name: 'home',
    meta: {
      hideInMenu: true,
      title: '首页',
      notCache: true
    },
    component: () => import('@/view/single-page/home')
  }
]

};
export const otherRouter = {
path: ‘/’,
name: ‘_home’,
redirect: ‘/home’,
component: Main,
meta: {

hideInMenu: true,
notCache: true

},
children: [

{
  path: 'home',
  name: 'home',
  meta: {
    hideInMenu: true,
    title: '首页',
    notCache: true
  },
  component: () => import('@/view/single-page/home')
}

]
};

export const page401 = {

path: '/401',
name: 'error_401',
meta: {
  hideInMenu: true
},
component: () => import('@/view/error-page/401.vue')

};
export const page500 = {

path: '/500',
name: 'error_500',
meta: {
  hideInMenu: true
},
component: () => import('@/view/error-page/500.vue')

};
export const page404 = {
path: ‘*’,
name: ‘error_404’,
meta: {

hideInMenu: true

},
component: () => import(‘@/view/error-page/404.vue’)
};

export const routers = [
loginRouter,
indexRouter,
page401,
page500,
page404,

];
routerJurisdiction().then((rel) => {
for(var i=0 ;i<rel.data.data.length;i++){

routers.push(
  {
    path: '#'+rel.data.data[i].f_code,
    name: rel.data.data[i].f_code,
    meta: {
      hide: true
    },
    component: Main,
    children:[
      {
        path: rel.data.data[i].f_code+'_page',
        name: rel.data.data[i].f_code+'_page',
        meta:{
          icon: rel.data.data[i].f_icon,
          title: rel.data.data[i].f_name,
        },
        component: () => import(rel.data.data[i].f_url)
      }
    ]
  },
);

}

});

export default routers

这样写,菜单中是出现了我读取到的内容,但是点击之后Route with name ‘company_page’ does not exist,就有这样的问题,请大牛们,问怎么解决?

回答:

注意这句,打包过程是不知道你的资源在哪儿的

component: () => import(rel.data.data[i].f_url)

暂无评论

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注