美文网首页
VUE解决跨域

VUE解决跨域

作者: MaJiT | 来源:发表于2020-09-15 18:11 被阅读0次

1.vue.config.js 修改

proxyTable: {
      '/apis':{
        target: 'http://127.1.1.1:2000, //A服务器地址
        changeOrigin: true,    //改变源路劲
        pathRewrite: {
          '^/apis': '/'
        }
      },
      '/common':{
        target: 'http://127.1.1.1:1000', //B环境的数据
        changeOrigin: true,    //改变源路劲
        pathRewrite: {
          '^/common': '/'
        }
      }
    }, 

2.使用

this.$axios({
    url: '/apis/user/login',    //  '/common/user/login',
    method: 'get', 
    }).then(res => {
      console.log('success');
    }).catch({
      console.log('error');
    })
});

相关文章

网友评论

      本文标题:VUE解决跨域

      本文链接:https://www.haomeiwen.com/subject/jgwfyktx.html