一. 使用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)
})
网友评论