配置
在配置文件中通过使用proxy代理解决请求跨域问题
server:{
// 跨域
proxy:{
'/api':{
target:'http://58.59.43.03:871/proxy/ythsj',
changeOrigin:true,
rewrite:(path) => path.replace(/^\/api/, '')
},
'/orderp':{
target:'http://dt.ywgb.youlishu.com',
changeOrigin:true,
rewrite:(path) => path.replace(/^\/orderp/, '')
},
'/datamUrl':{
target:'http://rz.ywgb.youlishu.com',
changeOrigin:true,
rewrite:(path) => path.replace(/^\/datamUrl/, '')
}
}
// 端口号
}
创建axios实例
export const instance = axios.create({
// 跨域
baseURL: '/api',
timeout: 5000
});
用async、await封装get、post请求
export const get = url => {
return async params => {
return instance.get(url, {
params
})
}
};
export const post = url => {
return async params => {
return instance.post(url, params)
}
}
请求地址
import { get, post } from "./_httpproxy"
// 事件
export const getEventTotalCount=get('/api/ythEvent/getEventTotalCount')
4.
![](https://img-blog.csdnimg.cn/img_convert/61f934162d29994b3d6f55dc5cff5ef4.png)