使用json-server

安装


npm install -g json-server

描述接口数据


在项目中新建一个test.json文件,用以指定/issues和/total接口返回的数据
\\ test.json
{
  "issues": [
    {
      "id": 101,
      "text": "something is not right"
    },
    {
      "id": 102,
      "text": "crash on login"
    }
  ],
  "total": {
    "data": {
      "exchange_count": "10",
      "share_count": "23",
      "patent_count": "7",
      "article_count": "37",
      "exchangeRecords": []
    },
    "success": true
  }
}

启动服务


json-server --watch test.json --port 9090


接下来,访问localhost:9090,我们可以看到如下页面

此时我们请求/issues和/total接口即可返回json文件中的指定数据了

猜你喜欢

转载自blog.csdn.net/goodgirl1991/article/details/54646665