当两个顺序请求发送并且第二个请求出错时我遇到问题 - >错误:“网络错误”例如:
OPTION : /meal/get 200 success
GET: /meal/get 200 success
OPTION: /message/get 200 get
dont send GET :/message/get
并显示错误
我检查了 OPTIONS 的标题响应:第一个选项的响应部分是真的,但第二个是错误的
我使用 php 作为我的后端,并且所有部分都真正工作
全局配置文件:
axios.defaults.headers.get['Accept'] = 'application/json'
axios.defaults.headers.common['Content-Type'] = 'application/json'
这是我的代码
axios({
method: 'get',
url: '/message/index',
data: {},
params: {
page: page
}
}).then(res => {
响应头:
Access-Control-Allow-Credentials true
Access-Control-Allow-Headers Origin, Accept, Content-Type, …, X-GR- Token, Accept-Language
Access-Control-Allow-Methods GET,POST,OPTIONS
Access-Control-Allow-Origin *
Access-Control-Expose-Headers X-Access-Token, X-Refresh-Toke…nation-Total-Count, X-Payload
Connection Keep-Alive
Content-Length 0
Content-Type text/html; charset=UTF-8
Date Mon, 11 Mar 2019 16:00:22 GMT
Keep-Alive timeout=5, max=100
Server Apache/2.4.27 (Win64) PHP/7.1.9
Status 200 OK
X-Powered-By PHP/7.1.9
不同组件中的每个请求
axios({
method: 'get',
url: '/meal/suggest',
data: {},
params: {}
}).then( res => {
console.log(res)
// this.rightSideData = res.data
}).catch(err => {
console.log(err)
console.log(err.response.data)
})
此请求的标头响应:
Connection Keep-Alive
Content-Length 876
Content-Type text/html; charset=UTF-8
Date Mon, 11 Mar 2019 16:00:23 GMT
Keep-Alive timeout=5, max=100
Server Apache/2.4.27 (Win64) PHP/7.1.9
X-Powered-By PHP/7.1.9