美文网首页
vue/cli 4 配置多个代理服务器

vue/cli 4 配置多个代理服务器

作者: 很好就这样吧 | 来源:发表于2021-11-17 16:07 被阅读0次

    vue.config.js

    module.exports = {
        publicPath: '/',
      
        outputDir: 'dist',
      
        assetsDir: 'static',
      
        filenameHashing: true,
      
        devServer: {
          open: true,  // 自动打开浏览器
      
          host: '127.0.0.1',
      
          port: 8081,
      
          https: false,
      
          hotOnly: false,
    
          disableHostCheck: true,
      
          proxy: {
              "/api": {
                  target: 'http://xxxxxxx', // 这个地址结尾我原本加了一个‘/’,然后一直报404,去掉就好了
                  changeOrigin: true,
                  pathRewrite: {
                      '^/api': '/'
                  }
              },
              '/bpi': {
                  target: "http://xxxxxx",
                  changeOrigin: true,
                  pathRewrite: {
                    '^/bpi': '/'
                }
              },
              '/cpi': {
                  target: 'http://',
                  changeOrigin: true,
                  pathRewrite: {
                    '^/cpi': '/'
                }
              }
          },
      
          before: app => {
          }
        },
        // 构建时开启多进程处理 babel 编译
        parallel: require('os').cpus().length > 1,
      
        // https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-pwa
        pwa: {},
      
        // 第三方插件配置
        pluginOptions: {}
      };
    

    在main.js里面,设置baseURL

    axios.defaults.baseURL = ''
    

    相关文章

      网友评论

          本文标题:vue/cli 4 配置多个代理服务器

          本文链接:https://www.haomeiwen.com/subject/xfgltrtx.html