Axios默认将数据发布到与应用程序部署在同一域上的服务器。但是,如果您需要将数据发布到另一个域,则需要将跨域选项设置为true。
以下是示例代码:
axios.post('http://example.com/api/data', { data: 'this is some data' }, { withCredentials: true, crossDomain: true }) .then(response => { console.log(response.data); }) .catch(error => { console.error(error); });
withCredentials选项指示Axios将包含凭据的Cookie发送到服务器。 crossDomain选项告诉Axios,即使在不同的域中,也要使用XMLHttpRequest对象进行请求。
上一篇:Axios将id设置为零
下一篇:Axios将我连接到错误的端口