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