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"},
...省略
]