0

在 mirajeJS 的帮助下,我们可以模拟路由,但是如果在 mirajeJS 中没有模拟这样的路由,是否可以重定向它并使用 axios 使用真实的服务器?

import {Server} from "miragejs";

new Server({
  routes() {
    this.namespace = "api/";
    this.get("test/router", () => {
      return [
        {name: "Angy", surname: "T."},
        {name: "Chris", surname: "B."},
        {name: "Juliana", surname: "Crain"}
      ];
    });
  }
});

也就是我想实现如下行为,我湿了test/router请求,但是如果用户发出任何其他没有锁定在Miraje中的请求,那么就去到真实服务器,也就是使用真实请求

4

1 回答 1

1

你可以使用这样的直通

new Server({
  routes() {
    this.namespace = "api/";
    this.get("test/router", () => {
      return [
        {name: "Angy", surname: "T."},
        {name: "Chris", surname: "B."},
        {name: "Juliana", surname: "Crain"}
      ];
    });
    // Allow unhandled requests on the current domain to pass through
    this.passthrough();
  }
});
于 2021-05-28T23:27:16.053 回答