pro2

ant design pro 2将umi.js和dva.js整合到一起了。

1. mock文件夹的作用

1.1 umi .js约定 mock 文件夹下的文件即 mock 文件

mock/user.js

export default {
    'GET /user':{name:"Jack"}
}

当访问http://localhost:8000/user时,返回{"name":"Jack"}

1.2 dva.js需要在 .roadhogrc.mock.js文件中进行配置,虽然目录中也有mock文件夹,但是只是单纯存放一些数据,然后将数据引入到 .roadhogrc.mock.js进行使用

.roadhogrc.mock.js

{
    'POST /api/users':(req,res)=>{
        setTimeout(()=>{
            res.send({success:true})
        },2000)
        
    }
}

1.3  ant-design-pro2.0将umi.js和dva.js整合到一起,ant-design-pro2目录下的mock文件夹和umi文件夹下的mock文件具有相同的功能。强调一下返回的数据格式不能是字符串,必须是json格式

F:\ant-design-pro-1\src\common\menu.js

{
    name: 'dashboard',
    icon: 'dashboard',
    path: 'dashboard',
    children: [
      {
        name: '分析页',
        path: 'analysis',
      },
      {
        name: '监控页',
        path: 'monitor',
      },
      {
        name: '工作台',
        path: 'workplace',
      },
    ],
  }

通过formatter()函数处理:

添加authority属性,authority:undefined任何人都可以访问,authority:admin,只有admin才可以访问;

处理path属性:前面添加"/"

{
    name: 'dashboard',
    icon: 'dashboard',
    path: '/dashboard',
    authority:undefined,
    children: [
      {
        name: '分析页',
        path: '/analysis',
        authority:undefined,
      },
      {
        name: '监控页',
        path: '/monitor',
        authority:undefined,
      },
      {
        name: '工作台',
        path: '/workplace',
        authority:undefined,
      },
    ],
  }

重定向菜单redirectData = [];经过getMenuData().forEach(getRedirect);

[{from:"/dashboard",to:"/dashboard/analysis"},
                    ...省略

]

猜你喜欢

转载自blog.csdn.net/Night_Emperor/article/details/82393356