使用 Axios 模拟适配器 GET 的问题

Problem with use of Axios mock adapter GET

我尝试使用 Axios 模拟适配器来模拟 GET 到 Web API,但是它不起作用。

api url 看起来像这样:

`/api/forms/${guid}`

我尝试使用正则表达式,但不起作用(可能与 d+ 有关):

mock.onGet('/\/api\/forms\/\d+/').reply((config) => {
    // the actual id can be grabbed from config.url
    console.log(config);
    return [200, {}];
});

这项工作:

mock.onGet('/users').reply((config) => {
    // the actual id can be grabbed from config.url
    console.log(config);
    return [200, {}];
});

正则表达式不应在 JavaScript 中引用。

试试这个:

mock.onGet(/\/api\/forms\/\d+/).reply((config) => {