我很確定一切都正確。我正在使用這些版本:
"axios": "^0.24.0",
"json-server": "^0.17.0",
我遵循了官方檔案。我db.json在根檔案夾中。
{
"users": [
{
"ID": 1,
"Username": "mike",
"Password": "User1Password"
},
{
"ID": 2,
"Username": "robert",
"Password": "User2Password"
}
]
}
我正在json-server使用此命令運行:
json-server --watch db.json --port 4000
每當我點擊時,http://localhost:4000/users我都會得到這個:
\{^_^}/ hi!
Loading db.json
Done
Resources
http://localhost:4000/posts
http://localhost:4000/comments
http://localhost:4000/profile
Home
http://localhost:4000
Type s enter at any time to create a snapshot of the database
Watching...
GET /users 404 4.800 ms - 2
但其余的終點如下:
http://localhost:4000/posts
http://localhost:4000/comments
http://localhost:4000/profile
作業得很好。請幫忙。
uj5u.com熱心網友回復:
根據要求將我自己的評論復制到答案中:
你說的db.json是在src檔案夾中。重要的是它位于您啟動服務器的同一檔案夾中。聽起來它在db.json其他地方創建了一個默認值并正在使用它。
uj5u.com熱心網友回復:
根據@user2740650
你說 db.json 在 src 檔案夾中。重要的是它位于您啟動服務器的同一檔案夾中。聽起來它在其他地方創建了一個默認的 db.json 并正在使用它。
第二個場景
將您的 db.json 檔案移動到 Public 檔案夾中并通過以下方式呼叫它: axios.get('db.json') .then(//...)
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/344114.html
