美文网首页
安装json-server

安装json-server

作者: 无知者3 | 来源:发表于2022-04-02 21:50 被阅读0次

    这个包可以快速帮我们搭建一个http服务,为什么搭建http服务呢?是因为我们使用axios的时候需要向服务端发送请求,github上可以搜索到。
    json-server

    1 安装

    npm install -g json-server
    

    2 创建 db.json文件

    {
        "posts": [
            { "id": 1, "title": "json-server", "author": "typicode" },
            { "id": 2, "title": "json-server", "author": "typicode" }
        ],
        "comments": [
            { "id": 1, "body": "some comment", "postId": 1 }
        ],
        "profile": { "name": "typicode" }
    }
    
    image.png

    3 开启json server

    json-server --watch db.json
    
    image.png

    4 访问

    4.1 get请求获取数据

    image.png
    image.png

    4.2 post新增数据

    image.png

    4.3 put修改数据

    image.png

    4.4 delete删除数据

    image.png

    相关文章

      网友评论

          本文标题:安装json-server

          本文链接:https://www.haomeiwen.com/subject/nyrxsrtx.html