我用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 resources_id,其中resource 是资源的名称。在你的情况下:
json-server db.json --id 'uuid'
关于javascript - Json-server 依赖于 uuid 而不是 id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57008239/