如何将 json 服务器与 reactjs 一起使用?



我已经安装了json-server:

npm install -g json-server

然后我创建了一个这样的db.json:

{
"employees": [
{
"id": 1,
"first_name": "Sebastian",
"last_name": "Eschweiler",
"email": "sebastian@codingthesmartway.com"
},
{
"id": 2,
"first_name": "Steve",
"last_name": "Palmer",
"email": "steve@codingthesmartway.com"
},
{
"id": 3,
"first_name": "Ann",
"last_name": "Smith",
"email": "ann@codingthesmartway.com"
}
]
}

我通过以下方式观看json服务器:

json-server --watch db.json 

但它不起作用。终端中的消息是:

无法加载,因为在此系统上禁用了运行脚本。 有关详细信息,请参阅about_Execution_Policies https:/go.microsoft.com/fwlink/?链接 ID = 135170。

发生了什么事?

您可以将 json-server 安装为开发依赖项

npm install -D json-server

然后你可以运行以下命令

npx json-server --watch db.json --port 3004

它会起作用。

最新更新