Vue Vue-cli post请求使用过程中的跨域问题

2022-09-17 10:38:57

vue-cli 实现前后端完全分离的情况下,出现的跨域问题
找到config下的index.js
找到proxyTable,添加代理

proxyTable:{'/api':{ 
		  target:'http://127.0.0.1:8081/',//源地址
		  changeOrigin:true,//是否跨域
		  pathRewrite:{'^/api':'http://127.0.0.1:8081/'//路径重写}}}

在调用时用自定义的名称代替 ip

this.$http.post('/api/test/login.do',{
				 username:this.login.username,
				 password:this.login.password}).then(result=>{var resData=result.data;});
  • 作者:卢本伟牛B
  • 原文链接:https://blog.csdn.net/qq_37169866/article/details/108140344
    更新时间:2022-09-17 10:38:57