1

json-server的简单使用

 2 years ago
source link: https://segmentfault.com/a/1190000040992001
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

json-server的简单使用

发布于 今天 11:51

此时文件夹中会创建一个package.json

cnpm init -y

然后我们在同级创建一个db.json
切记一定要有引号不然会报错

{
    "users": [{
            "name": "常吉孔",
            "age": 18
        },
        {
            "name": "范道矮",
            "age": 34
        },
        {
            "name": "博多叶",
            "age": 68
        }
    ],
    "computer": [{
            "id": 1,
            "name": "android"
        },
        {
            "id": 2,
            "name": "MacBook"
        },
        {
            "id": 3,
            "name": "Windows"
        }

    ]
}

cnpm i json-server -S

然后再package.json中替换掉test
说白了就是监听这个db.json文件

"scripts": {
    "dev": "json-server --watch db.json"
}

cnpm run dev

image.png


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK