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} ,
用 /api 代替源地址 :
this.$http.post('/api/user/login',{你要传入的参数},{emulateJSON:true}).then((res)=>{ }) .catch((res)=>{ })