使用json-server mock數(shù)據(jù)時遇到的問題:
當(dāng)在db.json中定義
{
"name": "Jack"
}
會報錯: json-server Type of "name" (string) is not supported.
原因與json-server的工作方式有關(guān)
直接暴露在JSON對象根目錄下的每個鍵都被視為json-server中的單獨(dú)URL。
需要使用對象或數(shù)組對象
{
"name": ["Jack"]
}
訪問 http://localhost:3001/name,頁面顯示["Jack"]