【发布时间】:2019-11-22 07:07:07
【问题描述】:
我使用json-server,我使用这样的数据:
{
"posts": [
{ "id": 1, "title": "json-server", "author": "typicode" }
],
"comments": [
{ "id": 1, "body": "some comment", "postId": 1 }
]
}
我想使用 uuid 而不是 id,像这样:
{
"posts": [
{ "uuid": 1, "title": "json-server", "author": "typicode" }
],
"comments": [
{ "uuid": 1, "body": "some comment", "postId": 1 }
]
}
但问题是 json-server 在搜索时使用 id 作为 主键,例如:
endpoint/posts/1
- 使用 id 就可以了
- 使用 uuid 不起作用
有没有办法让 json-server 依赖 uuid 而不是 id
【问题讨论】:
-
我不确定这是否能解决您的问题,但您可以使用
--id或-i(别名)标志设置id 属性。 (npmjs.com/package/json-server#cli-usage)
标签: javascript node.js json json-server