vue实现跨域请求的设置

前端之家收集整理的这篇文章主要介绍了vue实现跨域请求的设置前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
vue实现跨域请求,需要在vue.config.js里添加以下设置
     proxy: {
      '/service/rest': {    
        target: 'http://localhost:8080/autotable/service/rest',ws: true'^/service/rest':''
        }
    }
  }
其中 ,将changeOrigin设置为true,就不会存在无法跨域请求的问题了。
然后就可以直接在下面引用axios调用了。
import axios from '@/api/api';
export default {
    userList(params) {
        return axios.post('service/rest/api/user/logincode'

猜你在找的Web前端相关文章