vue-resource post請求后台接口報400(跨域問題解決方法)


1.打開config/index.js,在proxyTable中添寫如下代碼

proxyTable: { 

  '/api': {  //使用"/api"來代替"http://f.apiplus.c" 
        target: 'http://f.apiplus.cn', //源地址 
        secure: false,      // 如果是https接口,需要配置這個參數
        changeOrigin: true, //改變源 如果接口跨域,需要進行這個參數配置
        pathRewrite: { 
              '^/api': ' ' //路徑重寫 
        } 
   } 
}

2.在發送POST請求的options選項中添加 {emulateJSON:true} 即可:

this.$http.post('/api/user/login',{你要傳入的參數},{emulateJSON:true}).then((res)=>{


})
.catch((res)=>{

})


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM