在使用vue-cli时 我使用了跨域
vue.config.vue
module.exports = {
lintOnSave: false,
devServer: {
proxy: {
'/api': {
target: 'http://localhost:3000', // target host
ws: true, // proxy websockets
changeOrigin: true, // needed for virtual hosted sites
pathRewrite: {
'^/api': '' // rewrite path
}
},
},
},
};
但是我现在想请求其他网址的数据,但是他报错了
有没有哪位大神知道应该使用什么方法吗?
你应该是请求的远程地址吧,然后没走代理,但是你本地
localhost
请求它仍然是跨域的。所以,要不你就改target
的主机地址,请求的时候走/api
命中代理的逻辑。要不就CORS
配置一下,直接用XMLHTTPRequest
请求。