• 准备后端接口服务环境


    准备后端接口服务环境(了解)
    安装全局工具 json-server (全局工具仅需要安装一次)

    yarn global add json-server 或 npm i json-server  -g
    
    • 1

    代码根目录新建一个 db 目录
    在db目录新建 index.json 文件

    {
    "cart": [
     {
       "id": 100001,
       "name": "低帮城市休闲户外鞋天然牛皮COOLMAX纤维",
       "price": 128,
       "count": 1,
       "thumb": "https://yanxuan-item.nosdn.127.net/3a56a913e687dc2279473e325ea770a9.jpg"
     },
     {
       "id": 100002,
       "name": "网易味央黑猪猪肘330g*1袋",
       "price": 39,
       "count": 14,
       "thumb": "https://yanxuan-item.nosdn.127.net/d0a56474a8443cf6abd5afc539aa2476.jpg"
     },
     {
       "id": 100003,
       "name": "KENROLL男女简洁多彩一片式室外拖",
       "price": 128,
       "count": 2,
       "thumb": "https://yanxuan-item.nosdn.127.net/eb1556fcc59e2fd98d9b0bc201dd4409.jpg"
     },
     {
       "id": 100004,
       "name": "云音乐定制IN系列intar民谣木吉他",
       "price": 589,
       "count": 1,
       "thumb": "https://yanxuan-item.nosdn.127.net/4d825431a3587edb63cb165166f8fc76.jpg"
       }
    ]
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32

    进入 db 目录,执行命令,启动后端接口服务 (使用–watch 参数 可以实时监听 json 文件的修改)

    json-server  --watch  index.json
    
    • 1

    当服务启动后,可以访问http://localhost:3000/cart获取数据

  • 相关阅读:
    爬虫究竟是合法还是违法的?
    C++入门知识
    J-Link Device Support Kit
    Flink SQL --命令行的使用(02)
    LNMP架构
    REST风格
    GEE错误——Tile error: Arrays must have same lengths on all axes but the cat axis
    zemax---Ray Aberration(光线光扇图)
    MySQL 8.0.13升级到8.0.35记录 .NET
    React高级特性之RenderProps
  • 原文地址:https://blog.csdn.net/m0_53951384/article/details/134455116