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