Vue-cli 开发环境跨域代理设置、Vue-cli跨域代理

vue-cli 2.0 跨域代理设置

// config/index.js
const path = require('path')

module.exports = {
  dev: {
    proxyTable: {
      '/api': {
        target: 'http://localhost:8182', //目标域名
        // target: 'http://localhost:9920/',
        changeOrigin: true, // 是否允许跨域
        ws: true, // 如果要代理 websockets,配置这个参数
        pathRewrite: {
          '^/api': '' // 接口重写
        }
      },
    },
  },
}

vue-cli 3.0+ 跨域代理设置

// vue.config.js
devServer: {
  proxy: {
      '/api': {
          target: 'http://e.dxy.net',  // 后台接口域名
          ws: true,        //如果要代理 websockets,配置这个参数
          secure: false,  // 如果是https接口,需要配置这个参数
          changeOrigin: true,  //是否跨域
          pathRewrite:{
              '^/api': '/' // 接口重写
          }
      }
  }
}

你可能感兴趣的:(Vue-cli 开发环境跨域代理设置、Vue-cli跨域代理)