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,
        ... 
}

 

posted @ 2020-06-14 21:47  Peter_Yang0942  阅读(264)  评论(0编辑  收藏  举报