【问题标题】:How to use json server with reactjs?如何将 json 服务器与 reactjs 一起使用?
【发布时间】:2020-09-28 20:59:32
【问题描述】:

我已经使用以下方法安装了 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-server:

json-server --watch db.json 

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

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

发生了什么?

【问题讨论】:

  • 如果您转到链接并启用此docs.microsoft.com/en-gb/powershell/module/…
  • 如何启用?你能帮帮我吗?
  • 我已经设置好了:Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine -> A。但它不起作用消息:被拒绝。要更改默认 (LocalMachine) 范围的执行策略,请使用“以管理员身份运行”选项启动 Windows PowerShell。要更改当前用户的执行策略,请运行“Set-ExecutionPolicy -Scope CurrentUser”

标签: javascript json reactjs redux json-server


【解决方案1】:

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

npm install -D json-server

然后你可以运行下面的命令

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

它会起作用的。

【讨论】:

  • 我已经全局安装了 json-server(我没有使用 -D 标志)并且在 Visual Studio Code 的终端中运行 json-server 命令时遇到问题,但运行 @ 987654325@ 命令有效。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-18
  • 2014-03-16
  • 2020-06-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多