1.vite.config.ts 中添加如下代码:
export default defineConfig({
server: {
proxy: {
'/api': {
target: 'http://xxx.com/', // 实际请求地址
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, ""),
},
},
},
})
2.修改 axois 封装中的 baseURL:
baseURL:'/api',
3.api 请求接口示例
class api {
/* api 接口模块 */
public static user = {
getVerificationCode: () => Request.post('/api/Elogin/code'),
}
}