Git Product home page Git Product logo

Comments (1)

zkboys avatar zkboys commented on August 25, 2024

mock功能能是提供假接口,跟页面的path没有任何关系,mock接口定义好之后,使用上和真实后端接口没有区别。

编写mock数据:

mock在src/mock目录下编写,可以参考 mock-user-center.js;

使用mock接口:

比如mock-user-center.js中有个 'get /mock/user-center': (config) => {.....}
在组件中直接通过get方法,url为/mock/user-center调用即可:

this.props.ajax
    .get('/mock/user-center', {...params, pageNum, pageSize})
    .then(res => {
        console.log(res);
        if (res) {
            const {list: dataSource, total} = res;
            this.setState({
                dataSource,
                total,
            });
        }
    })
    .finally(() => this.setState({loading: false}));

注意:mock接口的url约定以/mock/开头,或在src/mock/url-config.js中配置,this.props.ajax会根据约定,区分调用mock接口,还是后端真实接口。

系统中只是提供了一个简单的mock功能,如果有后端接口了,需要修改url为后端真实接口,如果忘记修改,线上就404了,一般团队都会有一个mock平台,通过平台切换,前端并不需要在修改url。mock平台将mock数据从前后端中抽离出去单独维护,会使前后端开发协作更无缝、更友好。我司还未大量使用mock平台,有兴趣可以google一下~

from react-admin.

Related Issues (20)

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.