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)=>{

})

猜你喜欢

转载自www.cnblogs.com/lizhao123/p/9367876.html