1.打开config/index.js文件
module.exports = {
dev:{
}
}
2.在dev中找见proxyTable {}
module.exports = {
dev:{
proxyTable:{
'/api': {
target: 'http://baidu',
//设置你调用的接口域名和端口号 别忘了加http
changeOrigin: true,
pathRewrite: {
'^/api': ''
//这里理解成用‘/api’代替target里面的地址,后面组件中我们掉接口时直接用api代替 比如我要调用'http://baidu/user/add',直接写‘/api/user/add’即可
}
}
}
}
}
3.在组件中调用接口
this.$axios.post("/api/user/add",{
params:{
uname:dingding,
upwd:111111,
}})
.then(function(res){
console.log(res)
})
.catch(function(err){
console.log(err)
})