proxy代理

proxy在vue代理中的参数解释

     proxy: { //代理服务器,一般使用mock联调  与 vue-cli2.x的 proxyTable 一样的功能
            // '/': {
            //     target: "http://cqasia.860001.xyz:12091",
            // },
            "/dima_server/api": { 
                target: 'https://cqasia.860001.xyz:12092', //代理的地址
                pathRewrite: { 
                   "^/dima_server/api": "/dima_server/api" //将哪个地址代理到哪
                   },
                ws: false, //如果是要代理websockets,需要边为true
                changeOrigin: true, //是否跨域
            } 
          }

 

2.想查看是否代理成功

  利用before可以在控制查看到相关请求的数据

  devServer: {
        host: 'localhost',
        host: '0.0.0.0',
        port: '8081',
        https: true,
        before: (app) => {
            var url = require('url');
            app.use((req, res, next) => {
                function fullUrl(req) {
                    return url.format({
                        protocol: req.protocol,
                        host: req.get('host'),
                        pathname: req.originalUrl
                    });
                }
                console.log("req.url", fullUrl(req));
                next()
            })
        },
        proxy: { //代理服务器,一般使用mock联调  与 vue-cli2.x的 proxyTable 一样的功能
            // '/': {
            //     target: "http://cqasia.860001.xyz:12091",
            // },
            "/dima_server/api": {
                target: 'https://cqasia.860001.xyz:12092',
                pathRewrite: { "^/dima_server/api": "/dima_server/api" },
                ws: false,
                changeOrigin: true,
            },
       }

 

你可能感兴趣的:(web前端,vue)