【发布时间】:2019-04-22 01:20:53
【问题描述】:
我目前正在构建一个 nuxtjs 项目,其中 cockpit 作为我的无头 CMS。目前我发现使用 axios 提交帖子数据时存在问题。使用以下提取时,它按预期工作:
fetch('/api/forms/submit/Inschrijven?token=xxxtokenxxx', {
method: 'post',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
form: {
author: 'John Doe',
content: 'Something',
published: true
}
})
});
但遗憾的是,IE 不支持 fetch,IE 是该项目所需的浏览器。因此,我们使用 axios 来处理我们的请求,但在与上述相同的 url 上使用 axios.post 总是返回“找不到路径”。
axios.post('/api/forms/submit/Inschrijven?token=xxtokenxx', {
author: 'John Doe',
content: 'Something',
published: true
})
.then(entry => entry.json())
.then(entry => console.log(entry));
我怀疑 API 有问题,无法将其识别为真正的 json 帖子。这里有人知道为什么 axios.post 不起作用吗?
【问题讨论】:
-
你在设置 axios baseURL 吗?
-
是的,这已经完成了!
标签: vue.js axios fetch nuxt.js cockpit-cms