vuejs跨域请求解决方法

找到config/index.js目录:

proxyTable: {
    	'/api': {
            target: 'http://172.16.2.245/', //设置调用接口域名和端口号别忘了加http
            changeOrigin: true,
            pathRewrite: {
                '^/api': '/'   //这里理解成用‘/api’代替target里面的地址,组件中我们调接口时直接用/api代替
                                 // 比如我要调用'http://0.0:300/user/add',直接写‘/api/user/add’即可 代理后地址栏显示/
            }
        }
    },

微信公众号:jingfeng18 免费学习领取最新的前端学习资源
原文地址:https://www.cnblogs.com/qianduanshiping/p/11826870.html