1在根目录找到vite.congig.js文件
找到server对象添加:
proxy:{
'/api': {
target: 'http://test_labour.xingyuncm.cn/api',
changeOrigin: true,
rewrite: path => path.replace(/^\/api/, '')// 重写路径
},
},
可以根据接口设置多个:
proxy:{
'/api': {
target: 'http://test_labour.xingyuncm.cn/api',
changeOrigin: true,
rewrite: path => path.replace(/^\/api/, '')// 重写路径
},
// http://test_labour.xingyuncm.cn/auth/menus/index
'/auth': {
target: 'http://test_labour.xingyuncm.cn/auth',
changeOrigin: true,
rewrite: path => path.replace(/^\/auth/, '')// 重写路径
},
'/organization': {
target: 'http://test_labour.xingyuncm.cn/organization',
changeOrigin: true,
rewrite: path => path.replace(/^\/organization/, '')// 重写路径
},
'/user': {
target: 'http://test_labour.xingyuncm.cn/user',
changeOrigin: true,
rewrite: path => path.replace(/^\/user/, '')// 重写路径
},
'/grade': {
target: 'http://test_labour.xingyuncm.cn/grade',
changeOrigin: true,
rewrite: path => path.replace(/^\/grade/, '')// 重写路径
}
},
接下来就可以请求了
axios({
method:'post',
url:'/user/index/index',
data:qs.stringify({
})
}).then((res)=>{
}).catch((err)=>{
console.log(err);
})