Giter Site home page Giter Site logo

mock 支持 about dora-plugin-proxy HOT 8 CLOSED

dora-js avatar dora-js commented on June 9, 2024
mock 支持

from dora-plugin-proxy.

Comments (8)

sorrycc avatar sorrycc commented on June 9, 2024

引用 mockjs 的 mock 方法可以直接引文件:

import {mock} from 'mockjs/src/mock';
mock(data)

from dora-plugin-proxy.

sorrycc avatar sorrycc commented on June 9, 2024

其他的 mock 数据生成方案:

from dora-plugin-proxy.

pigcan avatar pigcan commented on June 9, 2024

请求 /movies/3 ,返回:

{
    "success": true,
    "data": {
        "id": 3,
        "name": "Melissa Moore"
    }
}

对于这个的实现 目前考虑到有 几种实现方式

  • 保持既定
var movie = {
  'id|+1': 1,
  'name': '@Name',
};

但是在代理层在 使用 Mock.mock(tmp) 得到的 json 内部进行截获 并修改. 但是目前能想到的劣势很明显,首先需要在用户配置 proxy.config.js 时候去申请将来需要去截获并修改的字段 诸如 'GET /movie/:data.id': {data: movie, success: true} , 使用 data.id 的含义是申明截获的 object 路径,当然劣势还会有,当一个字段需要在返回数据里多处修改时,以及需要修改的字段在 一个 collection 内.

  • 使用 Mock.mock(rurl, function(option){}) 这种方式,即用 function 的方式
  • 遇到这种场景,直接推荐用户使用目前 mock 的 function 的方式,如果要支持数据模板,把 Mock.mock 传递进去即可.

from dora-plugin-proxy.

sorrycc avatar sorrycc commented on June 9, 2024

请求 /movies/3 是否返回 id 为 3 的感觉不是很重要,可以不做处理,有需要让用户自己通过 function 或其他方式实现吧。

from dora-plugin-proxy.

pigcan avatar pigcan commented on June 9, 2024

确定下 :
诸如 分页 场景'GET /api/:cat' : object,该方式只是 实现了 Mock.mock(tmpl) 的调用, 在分页场景下并不能适用. 因为 :cat 抑或 currentPageNumber 并不能传递进来

如果要实现上述分页需求 让用户 去用 function 实现 . 即 'GET /api/:cat' : function ,在这种模式下 function 内传入三个参数 req, callback ,Mock.mock (req 内会注入 params) ?

from dora-plugin-proxy.

pigcan avatar pigcan commented on June 9, 2024

如果这样的话 'GET /api' : object 显得很单一 o.o

from dora-plugin-proxy.

sorrycc avatar sorrycc commented on June 9, 2024

从使用的角度整理下看怎么用更好呢?

from dora-plugin-proxy.

pigcan avatar pigcan commented on June 9, 2024

可以我去整理下 各种场景

from dora-plugin-proxy.

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.