欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

fastMock平台模拟接口

程序员文章站 2024-03-24 10:42:52
...

应用场景

由于有时候开发的时候后台接口赶不上,只能通过前端制造假数据来模拟,又不想下载mockjs来进行接口模拟。

  1. Mock平台网址:https://fastmock.site/#/projects
  2. fastmock使用指南: https://marvengong.gitee.io/fastmock-docs/
  3. fastmock支持mockjs语法。
  4. mockjs网址:https://github.com/nuysoft/Mock/wiki/Getting-Started

上一段自己写的mock代码:

{
  "code": "0000",
  "data": {
    "pageNo": function({
      _req, //_req表示request  _req.query表示get的参数 _req.params表示post参数
      Mock
    }) {
      return _req.query.pageNo || 1;
    },
    "totalRecord": "21",
    "pageSize": function({
      _req,
      Mock
    }) {
      return _req.query.pageSize || 10;
    },
    "list|10": [{
      "id|+1": 1,
      "img": "https://picsum.photos/@integer(1, 1500)",
      "name": "@[email protected](2)",
      "doctor_hospital": "南京@cword(2)医院",
      "porject": function({
        _req,
        Mock
      }) {
        let arr = ["过敏",
          "肺炎", "湿疹", "黄疸", "消化不良", "腹泻", "发热","鼻炎", "哮喘", "支气管炎", "幼儿急诊", "乳糖不耐受", "手足口病"
        ];
        return _req.query.project ? arr[_req.query.project] : arr[Mock.mock("@integer(0,6)")];
      },
      "price": "@float(10,100,10,100)",
      "hobby": ["坐疮",
        "尖锐湿疣", "甲癣", "足癣", "股癣", "脂溢性皮炎", "过敏"
      ],
      "star": "@integer(2, 5).00",
      "monthAnswer": "@integer(100, 250)",
      "monthChufang": "@integer(100, 250)",
      "AnswerTime": "@integer(1,5)",
      "tags": ["教授", "快速响应"],
      "coupon": "@boolean( 1, 5, true )",
      "picPrice": "@integer(0, 100)",
      "callPrice": "@integer(0, 100)",
      "hosLevel": "@boolean( 1, 10, true )",
    }]
  },
  "desc": "成功"
}

返回数据

点我查看

提醒

这个网址提供的接口在vue跨域是会直接报错代理错误的,这个接口是不用跨域的,直接访问即可