[resolve] mock.js cannot intercept Mini Program's request

Business background

Front and back end separate developers
want mock.js to intercept my request
and then return test data
and so on, after the backend has finished writing the interface, remove mock.js

.

Business Code

 const Mock = require("mockjs");
 Mock.mock("http://www.23.com", {
            "list|10": ","
          });
          wx.request({
            url: "http://www.23.com",
            complete (res) {
              console.log(res);
            }
          });

troubles encountered

  • template data of mock can be generated normally in Mini Program
  • but the initiated request is not intercepted, but is directly requested to www.23.com .

question

  • isn"t Mini Program"s request based on XHR? Why can"t you intercept it? is there any way for mock.js to intercept Mini Program"s request
  • or is there any other tool other than mock.js that can achieve similar functionality? Simultaneously supports various platforms (Mini Program, web pages, etc.)
Mar.11,2021

just start a json-server service yourself

is a module of node


No, Mini Program is not a browser environment.
request is neither XHR nor ajax.
another feasible method is to use mockjs, to mock the data based on the content returned by response, and then retrun it out.

digression:
personally, I feel that the official request writing is more tedious, so I use fly components to replace request,. If you are interested, you can learn about it.
one of the developers of Mini Program (using fly for http encapsulation)

Menu