初始化react-ts版项目
npx create-react-app jira --template typescript
react中使用绝对路径
// tsconfig.json
{
"compilerOptions": {
"baseUrl": "./src",
},
}
JSON Server 启动本地node服务mock数据
npm i json-server -g
根目录新增db.json
{
"users": []
}
执行命令
json-server --watch db.json
得到
http://localhost:3000/users
get请求
post请求 新增数据
会发现在db.json中自动生成
配置命令
// package.json
"scripts": {
"json-server": "json-server __json_server_mock__/db.json --watch"
},
npm run json-server