- 所有接口都是以 http://love.liushuaiyang.com 开头的
- 所有接口都没有处理跨域,如果要在vue项目中使用 , 需要配置跨域,详细看:
比赛相关接口:
返回的数据信息:
| 字段 | 类型 | 备注 |
|---|---|---|
| id | int | 城市id |
| cityName | string | 城市名称 |
| totalConsumption | int | 总消费额 |
| month | int | 月份 |
| provinceId | int | 省份id |
| provinceName | string | 省份名称 |
1.根据传入的月份获取对应月份的城市消费数据
url:/api/city/getData
请求方式:**POST**
请求参数:
| 字段 | 类型 | 是否必须 | 备注 |
|---|---|---|---|
| start | string | 是 | 起始月份 |
| end | string | 是 | 结束月份 |
请求示例:
- 使用
axios发送post请求 ```javascript mounted(){ axios.post(‘/api/city/getData’,{ start:”02”, end:”06” }).then(res =>{ console.log(res) }) }
//使用async await关键字 async mounted(){ const resp = await axios.post(‘/api/city/getData’,{ start:”02”, end:”06” }) console.log(resp) }
2. 使用`fetch` api(H5中新增的发送网络请求的api) 发送 `post` 请求```jsonmounted(){fetch('/api/city/getData',{method:"POST",body:JSON.stringify({start:"02",end:"06"}),headers:{"Content-Type":"application/json"}}).then(res => res.josn()).then(data => console.log(data))}//使用async await关键字async mounted(){const resp = await fetch('/api/city/getData',{method:"POST",body:JSON.stringify({start:"02",end:"06"}),headers:{"Content-Type":"application/json"}}).then(res => res.josn());console.log(resp);}
返回:
{"msg": "获取数据成功",data: [{"id": 4,"cityName": "阿克苏地区","totalConsumption": 87658,"month": 2,"provinceId": 6,"provinceName": "澳门特别行政区"},{"id": 23,"cityName": "广安市","totalConsumption": 52530,"month": 4,"provinceId": 4,"provinceName": "江西省"},...}
2.根据城市id查询到某个城市的数据
url:/api/city/:id:id 就是 你要查询的 城市id
请求方式:GET
请求参数:无
请求示例:
使用 axios 发送 get 请求
mounted(){//请求 id 为 3 的城市消费数据axios.get('/api/city/3').then(res =>{console.log(res)})}//使用async await关键字async mounted(){const resp = await axios.post('/api/city/3')console.log(resp)}
返回:
{"data": {"id": 3,"cityName": "山南地区","totalConsumption": 72731,"month": 5,"createdAt": "2022-01-03T11:58:35.000Z","updatedAt": "2022-01-03T11:58:35.000Z","deletedAt": null,"ProvinceId": 6},"msg": "查询成功"}
love 接口
一见钟情
url:/api/love/lsy 或者 /api/love/sjm
请求方式:GET
请求参数:无
请求示例:
使用 axios 发送 get 请求
mounted(){axios.get('/api/love/lsy').then(res =>{console.log(res)})}//使用async await关键字async mounted(){const resp = await axios.post('/api/love/lsy')console.log(resp)}
返回:
fall in love at first sight
最好的我们
url:/api/love/lsy&sjm
请求方式:GET
请求参数:无
请求示例:
使用 axios 发送 get 请求
mounted(){axios.get('/api/love/lsy&sjm').then(res =>{console.log(res)})}//使用async await关键字async mounted(){const resp = await axios.post('/api/love/lsy&sjm')console.log(resp)}
返回:
刘帅洋 & 史佳美
