我一直在试图弄清楚如何让这个 Vue 项目与 Lyft API 一起工作。我已经能够从三足过程中成功创建 Auth Token,但是我无法https://api.lyft.com/v1/ridetypes
从localhost:8080
. 它确实适用于Postman。
它一直在说:
从源“ http://localhost:8080 ”访问“ https://api.lyft.com/v1/ridetypes?lat=37.7752315&lng=-122.418075 ”的 XMLHttpRequest已被 CORS 策略阻止:对预检请求的响应不'不通过访问控制检查:请求的资源上不存在'Access-Control-Allow-Origin'标头。
我曾尝试使用vue.config.js
文件做代理:
module.exports = {
devServer: {
proxy: {
'/lyftapi': {
target: 'https://api.lyft.com/v1',
ws: true,
changeOrigin: true
}
}
}
}
我一直在 Stack Overflow 的其他地方,这是最接近我的问题的地方,但没有答案。
有什么建议么?
Axios 接听电话
axios.get('/ridetypes', {
baseURL: 'https://api.lyft.com/v1',
headers: {
'Authorization': this.lyftToken,
},
params: {
lat: lat.toString(),
lng: long.toString()
}
})
如果这意味着什么,我可以成功地进行 GET 调用来检索 Uber 产品,但不是 Auth Token(除非它来自 Postman)。