webpack解决本地跨域问题(使用proxy)

在Vue工程的config/index.js文件增加配置:

dev: {
        // Paths
        assetsSubDirectory: 'static',assetsPublicPath: '/',
        proxyTable: {
            '/api': {
                target: 'http://localhost:8087',
                pathRewrite: {
                    '^/api': ''
                },
                changeOrigin: true,
                secure: false, // 接受 运行在 https 上的服务
            }
        },
        host: '127.0.0.1', // can be overwritten by process.env.HOST
        port: 8080,
        ... 
}
原文地址:https://www.cnblogs.com/peter-web/p/13127211.html