Comments (1)
mock功能能是提供假接口,跟页面的path没有任何关系,mock接口定义好之后,使用上和真实后端接口没有区别。
编写mock数据:
mock在src/mock目录下编写,可以参考 mock-user-center.js;
使用mock接口:
比如mock-user-center.js中有个 'get /mock/user-center': (config) => {.....}
在组件中直接通过get方法,url为/mock/user-center
调用即可:
this.props.ajax
.get('/mock/user-center', {...params, pageNum, pageSize})
.then(res => {
console.log(res);
if (res) {
const {list: dataSource, total} = res;
this.setState({
dataSource,
total,
});
}
})
.finally(() => this.setState({loading: false}));
注意:mock接口的url约定以/mock/
开头,或在src/mock/url-config.js中配置,this.props.ajax会根据约定,区分调用mock接口,还是后端真实接口。
系统中只是提供了一个简单的mock功能,如果有后端接口了,需要修改url为后端真实接口,如果忘记修改,线上就404了,一般团队都会有一个mock平台,通过平台切换,前端并不需要在修改url。mock平台将mock数据从前后端中抽离出去单独维护,会使前后端开发协作更无缝、更友好。我司还未大量使用mock平台,有兴趣可以google一下~
from react-admin.
Related Issues (20)
- 大佬,ralib的Table 我用rowClassName貌似不起作用呀! HOT 4
- 才发现v5版本里,角色管理功能中的菜单树控件不太对劲! HOT 2
- ajax.js的 withDefaultSettings 中怎么拿到请求的url? HOT 2
- styleName定义子级无法生效 HOT 2
- 通过NavLink跳转的页面无法切换面包屑! HOT 5
- layout的logo参数无法使用jsx HOT 1
- 麻烦问下,表格 columns 里的操作列按钮,可以使用 Permission 组件 来控制按钮的显示嘛? HOT 2
- 啥时候支持一波 TS ? HOT 1
- ajax.js 响应拦截不生效 需要修改什么地方吗 HOT 5
- 为什么在线预览的样子和文档中的截图不一样呢 HOT 1
- PageContent -> Tabs -> Table 这样一个层级组件 当点击Tabs来回切换时 table 下面的分页组件会丢失 页面不可滑动 HOT 2
- TopMenu 模式下selectedMenuPath无效,刷新页面,二级菜单仍不能选中 HOT 1
- 动态路由,path一样 传参不同 菜单选中的问题 HOT 7
- 请问左侧菜单收起时显示图标,在哪修改呢
- ra-lib不再维护了么,没有仓库了 HOT 4
- 请求会被一直挂起
- 开源协议是怎么样的? HOT 1
- 组件文档无法查看
- 列表页跳转详情页,当刷新页面菜单不选中 HOT 7
- 详情页左侧菜单如何选中列表页菜单
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-admin.