vue-cli 2.x和3.0正向代理跨域

vue-cli3.0 需要自己去手动添加vue.config.js文件

//vue-cli 3.0中
 devServer: {
    port: 8080, // 端口号
    host: 'localhost',
    https: false, // https:{type:Boolean}
    open: true, //配置自动启动浏览器
    // proxy: 'http://localhost:4000' // 配置跨域处理,只有一个代理
    proxy: {
        '/api': {
            target: 'http://localhost:3000',
            ws: true,
            changeOrigin: true
        }
    },  // 配置多个代理
}
//vue-cli 2.x dev中
proxyTable: {
      '/api': {
        target: 'http://localhost:3000/',
        // pathRewrite: {
        //   '^/api': ''
        // }
      }
    },

猜你喜欢

转载自blog.csdn.net/a_passing_traveller/article/details/88238129
今日推荐