【发布时间】:2017-11-14 12:35:35
【问题描述】:
我正在使用 Vue 和 Axios 向 Square API V2 发出客户端请求。我的Vue组件如下:
import axios from 'axios';
export default {
mounted() {
var instance = axios.create({
baseURL: 'https://connect.squareup.com/v2/',
timeout: 1000,
headers: {
'Authorization': 'Bearer xxxxxxxxxxxxxxxxx',
'Accepts': 'application/json',
'Content-Type': 'application/json'
}
});
instance.get('catalog/list')
.then(function (response) {
console.log(response);
}) ;
}
}
但是,当我拨打电话时,我收到以下错误:
Failed to load https://connect.squareup.com/v2/catalog/list: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://local-env.dev' is therefore not allowed access. The response had HTTP status code 403.
该错误表明 Square 端必须进行一些配置,但我没有看到将域列入白名单等的机会。
之前有没有人遇到过这个错误,无论服务如何,如果有,您是如何解决的?
【问题讨论】:
标签: laravel vue.js axios square