vue中發的axios post請求,參數帶冒號:且報錯blocked by CORS policy

post請求報錯
在這裏插入圖片描述
status:failed
在這裏插入圖片描述

在這裏插入圖片描述
方法1
安裝qs
npm install qs

api:
config.headers['Content-Type'] = 'application/json'

zujian.vue:
import qs from 'qs'
let param={
   postCode:this.$route.query.pc,
 }
 requestReplypost(qs.parse(param)).then(response=>{
   this.postList.push(response)
   this.contp=''
 })

方法2

api.js:
axios.defaults.headers['Content-Type'] = 'application/json';

zujian.vue:
(get,post傳參形式不同)
let param={
 phoneNo:this.phoneNo,
  captcha:this.captcha
}
this.$http({
  method:'post',
  url:'http://xx.x.x.x:8600/god/capt',
  headers:{
    'Content-Type':'application/json'
  },
  data:JSON.stringify(param)
}).then((res)=>{
  document.getElementById("btnp").disabled=false;
  let sss=res.data})
  
this.$http({
  method:'get',
  url:'http://xx.x.x.x:8600/god/Inout?residentID='+this.residentID+'&type='+this.type,
  headers:{
    'Content-Type':'application/json'
  },
  // data:JSON.stringify(param)
}).then((res)=>{
  let data=res.data})
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章