首页 > webpack-dev-server 如何解决跨域请求!!

webpack-dev-server 如何解决跨域请求!!

1.loaclhost:8080 webpack-dev-server 本地服务器,接口请求地址是api.xxx.com,现在就是无法在本地请求远程服务器上的接口。

XMLHttpRequest cannot load http://api.xxx.com/v1/f/shares.
 No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access. The response had HTTP status code 403.

有找过相关资料。配置不造是错了还是什么不起作用。

    entry:[
        'webpack/hot/only-dev-server',
        './src/main.js'
    ],
    devServer: {
        hot: true,
        inline: true,
        proxy: {
            '*': {
                target: 'localhost:8080',
                host:'http://m.xxx.com',
                secure: false,
            }
        }
    },

changeOrigin: true
target: http://api.xxx.com

然后改成你本地引用的地址,比如/api/
其他地方调用的时候,就写ajax('/api/xxx')之类的

【热门文章】
【热门文章】