跨域都有什么解决办法呀?

2021-01-28 16:33发布

6条回答
孙哈哈
2021-02-22 15:15

vue配置反向代理解决跨域问题。

配置:config/index.js中的proxyTable

dev{

proxyTable: {

      '/api': {

        target: 'http://192.168.0.1:200', // 要代理的域名

        changeOrigin: true,//允许跨域

        pathRewrite: {

          '^/api': '' // 这个是定义要访问的路径,名字随便写

        }

   }

}

使用时:

// /api/getMenu相当于*http://192.168.0.1:200/getMenu

 // /api相当于http://192.168.0.1:200

 this.$http.get("/api/getMenu", {

 }

 .then(res => {

 })

 .catch(function(error) {

 });


一周热门 更多>