vue配置代理(vue.config.js)

const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
    transpileDependencies: true,
    //如果是hash模式, publicPath:"";如果是history, publicPath:"/"
    publicPath: "/",
    //打包的文件夹目录
    outputDir: "dist",
    // 打包之后的入口文件
    indexPath: "index.html",
    //静态资源目录
    assetsDir: "assets",
    //配置代理
    devServer: {
        proxy: {
            // "/api": {
            //     target: "http://hyzc-gateway-dev.apps.bjdev.ocpx.cnooc",
            //     ws: true,
            //     changeOrigin: true
            // },
            // 两种写法都可以
            // 代理请求, 匹配所有以/uums开头的请求
            "/uums": {
                // 目标服务器,所有以/uums开头的请求接口代理到目标服务器
                target: "http://hyzc-gateway-dev.apps.bjdev.ocpx.cnooc", //代理的地址(ip+端口号)
                ws: true,
                changeOrigin: true,//是否跨域
                // 重写路径,此时用于匹配反向代理的/uums可以替换为空 也可以理解为( “/uums”代替target里面的地址,后面组件中我们调接口是直接用uums代替)
                // {比如我要调用 ‘http://hyzc-gateway-dev.apps.bjdev.ocpx.cnooc/user/info’  直接写成 ‘/uums/user/info’}
                pathRewrite: {
                    "^/uums": ""
                },
            },
            '/hyzcBusi': {
                target: 'http://hyzc-gateway-dev.apps.bjdev.ocpx.cnooc/hyzcBusi',
                changeOrigin: true,
                pathRewrite: {
                    '^/hyzcBusi': ''
                }
            }
        }
    }
})

猜你喜欢

转载自blog.csdn.net/qq_48294048/article/details/130382196