一. 使用Charles实现mock数据
- 桌面创建
todolist.json文件
➜ ~ cd Desktop
➜ Desktop touch todolist.json
- 编辑
todolist.json文件
["Dell", "Lee", "Imooc"] - 打开
Charles代理
Charles-Proxy-macOS Proxy - 配置
Charles本地代理
①Charles-Tools-Map Local Settings-add
② 添加请求代理映射
image.png
- 使用
axios请求mock数据
① 安装axois
➜ my-react-app git:(master) ✗ yarn add axios
注释:也可以使用npm install axios --save安装。
② 使用axios请求数据
import axios from 'axios'
//省略...
axios.get('/api/todolist')
.then(data => {
console.log(data)
})
.catch(err => {
console.log(err)
})












网友评论