1、下载mockjs 推荐mock工具: charles。
cnpm install --save-dev mockjs
2、下载axios
cnpm install --save-dev axios
3、新建文件/utils/mockdata.js,更多官网实例
import Mock from 'mockjs'
Mock.mock('/list', {
"object|2-4": {
"110000": "北京市",
"120000": "天津市",
"130000": "河北省",
"140000": "山西省"
}
})
4、引入App.js
import './utils/mockdata'
5、使用
import React, { Component } from 'react'
import axios from 'axios'
class HocData extends Component {
constructor (props) {
super(props)
axios.get('/list')
.then(res => {
console.log(res.data)
})
}
render () {
return (
<div>HocData</div>
);
}
}
export default HocData