Mock
Mock copied to clipboard
怎样支持rest url 变量呢?
问题描述: Mock.mock('/customer/{id}', 'DELETE', function)其中id为变量, 在function中需要使用这个id变量进行模拟数据返回, 应该怎么做呢? 多谢
可以参考以下代码:
get: https://example.com/api/{id}/list
这里以返回纯数组为例:
// mock
[
function ({_req}) {
const ID_MAP = {
'a': [1, 2, 3, 4],
'b': [5, 6, 7, 8],
'c': [4, 3, 2, 1],
}
return ID_MAP[_req.params.id]
}
]