vue3 vite proxy代理用法

1)vite.configs.ts文件

server: {
    
    
     host: "0.0.0.0",
     port: 4001, // 设置服务启动端口号
     open: true, // 设置服务启动时是否自动打开浏览器
     cors: true, // 允许跨域

     proxy: {
    
    
         // 此处为抽取的接口 端口后的统一部分
         // 例如: http://199.199.9.9:8080/mars/v1    http://199.199.9.9:8080/mars/v2
         // [/mars]为统一部分,下面就以 /mars 开启
         '/mars':{
    
    
                 target: "http://210.72.137.240:30006",
                 // rewrite: (path) => path.replace('/api/', '/'),
                 changeOrigin: true,
             }
     }
}
  1. 使用时
// /mars就会被识别到,并替换
 axios.post('/mars/v1').then((res) => {
    
    

猜你喜欢

转载自blog.csdn.net/weixin_39423672/article/details/125005540