当前位置: 首页 > article >正文

mock 数据( json-server )

json-server 实现数据 mock

实现步骤:

1. 在项目中安装 json-server

npm install -D json-server

2. 准备一个 json 文件

   server/data.json

{"posts": [{ "id": "1", "title": "a title", "views": 100 },{ "id": "2", "title": "another title", "views": 200 }],"comments": [{ "id": "1", "text": "a comment about post 1", "postId": "1" },{ "id": "2", "text": "another comment about post 1", "postId": "1" }],"profile": {"name": "typicode"}
}

3. 添加启动命令

"scripts":{"server": "json-server ./server/data.json --port 8888"
}

4. 访问接口进行测试

npm run serve
  const [commentList, setCommentList] = useState([]);useEffect(() => {async function getList() {const res = await axios.get("http://localhost:8888");setCommentList(res.data);}getList();}, []);

http://www.lryc.cn/news/2378652.html

相关文章:

  • Java多线程编程中的常见问题与陷阱汇总
  • ARP Detection MAC-Address Static
  • gcc/g++常用参数
  • nginx配置之负载均衡
  • 相机Camera日志分析之十一:高通相机Camx hal预览1帧logcat日志process_capture_result详解
  • Python函数库调用实战:以数据分析为例
  • 去年开发一款鸿蒙Next Os的window工具箱
  • 顶层设计-IM系统架构
  • 信任的进阶:LEI与vLEI协同推进跨境支付体系变革
  • 安全性(三):信息安全的五要素及其含义
  • PHP 与 面向对象编程(OOP)
  • Axios全解析:从基础到高级实战技巧
  • EXO 可以将 Mac M4 和 Mac Air 连接起来,并通过 Ollama 运行 DeepSeek 模型
  • 数据库故障排查指南
  • RBTree的模拟实现
  • docker-compose——安装mongo
  • Vue 3.0中响应式依赖和更新
  • uniapp|实现获取手机摄像头权限,调用相机拍照实现人脸识别相似度对比,拍照保存至相册,多端兼容(APP/微信小程序)
  • JavaScript【7】BOM模型
  • [强化学习的数学原理—赵世钰老师]学习笔记02-贝尔曼方程
  • 使用Spring Boot与Spring Security构建安全的RESTful API
  • 深入理解构造函数,析构函数
  • Day 16
  • 摄影构图小节
  • DAY 28 类的定义和方法
  • RAG数据处理:PDF/HTML
  • 机器学习 day04
  • 蓝牙耳机什么牌子好?倍思值得冲不?
  • 机器学习-人与机器生数据的区分模型测试-数据处理 - 续
  • ESP系列单片机选择指南:结合实际场景的最优选择方案