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/, '')
            }
        }
    }
})

 

posted @ 2022-12-12 14:53  奔跑的哈密瓜  阅读(2704)  评论(0编辑  收藏  举报