1. vite.config.ts或者vite.config.js文件

server: {
      port: 3001,
      host: '0.0.0.0',
      open: true,
      proxy: {
        // 代理配置
        '/api': {
          target: 'https://localhost:44342',
          changeOrigin: true,//允许跨域
          secure:false,//解决自签名证书错误
          rewrite: (path) => path.replace(/^\/api/, ''),
        },
      },
    },

2. axios中的baseURL设置为'/api'即可

 posted on 2023-01-05 10:49  gwjieiee  阅读(975)  评论(0编辑  收藏  举报