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’即可 代理后地址栏显示/
            }
        }
    },

猜你喜欢

转载自blog.csdn.net/qq_35858830/article/details/80174801