Mock icon indicating copy to clipboard operation
Mock copied to clipboard

怎样支持rest url 变量呢?

Open zhangqqqf opened this issue 9 years ago • 1 comments

问题描述: Mock.mock('/customer/{id}', 'DELETE', function)其中id为变量, 在function中需要使用这个id变量进行模拟数据返回, 应该怎么做呢? 多谢

zhangqqqf avatar Mar 21 '17 03:03 zhangqqqf

可以参考以下代码: 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]
    }
]

lizhiiyongmfk avatar Mar 29 '18 04:03 lizhiiyongmfk