Code Monkey home page Code Monkey logo

mock-api's Introduction

初始化

将该文件放在根目录的config文件夹下,与webpack设置的文件同级。把对应的mock数据放在根目录的mock文件夹下。

需要设置两个process.env变量,一个是MOCK一个是PROXY。这里是通过env-cmd来设置变量,也可以通过cross-env或者dot-env。MOCK是用于打开该配置,PROXY是用于将请求先转发至本地webpack-dev-server。

在webpack-dev-server的配置里,将该中间件覆盖对应的before配置即可。

原理

通过重写webpack-dev-server的before配置,捕获对应的url请求,判断对应的请求参数是否相同,如果相同就返回mock数据

mock-api's People

Contributors

wind4gis avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.