vite配置反向代理
在vite官网中有详细的介绍,下面是官网地址。可直接查看
https://cn.vitejs.dev/config/server-options.html#server-proxy
代码中实现,在vite.config.ts中进行配置
import { defineConfig } from 'vite'//引入defineConfig
import vue from '@vitejs/plugin-vue'
export default defineConfig({
plugins: [vue()],
server: {
https: false,
proxy: {
'/image': {
target: 'https://xxxx.com/api', // 接口的域名
secure: false, // 如果是https接口,需要配置这个参数
changeOrigin: true, // 如果接口跨域,需要进行这个参数配置
rewrite: path => path.replace(/^\/image/, '')
}
}
}
})

浙公网安备 33010602011771号