vue跨域的问题,在开发环境下

找到config文件夹下的index.js

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

猜你喜欢

转载自www.cnblogs.com/MiaDeng/p/9759222.html