1,註釋main.js下的
if (process.env.NODE_ENV !== 'production') require('@/mock')
2.設置跨域
vue.config.js裏
// devServer: {
// proxy: 'http://xxxxxx/api/'
//}
3.設置headers頭
lib/axios.js文件裏,刪除content-type項,系統已內置,重複發送有錯
4. 設置請求地址
src/config/index.js文件裏
在axios.post請求中,post請求會先請求OPTIONS請求,檢測是否跨域,用 Access-Control-Allow-Origin 來檢驗,若允許,則再次post請求,並且post請求頭和post響應頭一一對應,post請求頭不應有超出post響應頭的數據,post請求頭可以沒有post響應頭中的數據
post響應頭
Access-Control-Allow-Headers |
X-Requested-With, Version, X-Token, content-type |
post請求頭
Content-Type |
application/json; charset=UTF-8 |
X-Requested-With |
XMLHttpRequest |
X-Token |
Bearer sdfsdf |