vue实现跨域请求,需要在vue.config.js里添加以下设置
     proxy: {
      '/service/rest': {    
        target: 'http://localhost:8080/autotable/service/rest',
        ws: true,
        changeOrigin: true,
        pathRewrite:{
            '^/service/rest':''
        }
    }
  }
其中 ,将changeOrigin设置为true,就不会存在无法跨域请求的问题了。
然后就可以直接在下面引用axios调用了。
import axios from '@/api/api';
export default {
    userList(params) {
        return axios.post('service/rest/api/user/logincode', params);
    },
  
};

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-27
  • 2021-10-19
  • 2021-06-14
  • 2021-04-17
  • 2022-12-23
  • 2022-12-23
  • 2021-06-29
相关资源
相似解决方案