安装
cd 项目名
版本0.18.0
npm install axios@0.18.0 --save
新建 request.js
import axios from 'axios'
封装 request.js
import axios from 'axios'
export function request(config) {
const instance = axios.create({
baseURL: ' https://api.coindesk.com/v1/bpi/',
})
//2.1请求拦截
instance.interceptors.request.use(config => {
console.log(config);
return config
}, err => {
console.log(err);
})
//2.2响应拦截
instance.interceptors.response.use(res => {
console.log(res);
return res.data
}, err => {
console.log(err);
})
// 发送真正的网络请求
return instance(config)
}
新建home.js
import {request} from "./request";
export function getHomeMultidata(){
return request({
url:'home/data?page=1&page_size=5&sort=new'
})
}
export function getHomeGoods(){
return request({
//url:'home/data?type=sell&page=3',等价于下面
url:'home/data',
params:{
type:'sell',
page:3
}
})
}
function test (){
}
|