首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >vue实现跨域请求的设置

vue实现跨域请求的设置

作者头像
朱季谦
发布于 2019-09-18 14:44:31
发布于 2019-09-18 14:44:31
1.9K0
举报

vue实现跨域请求,需要在vue.config.js里添加以下设置

代码语言:javascript
复制
     proxy: {
      '/service/rest': {    
        target: 'http://localhost:8080/autotable/service/rest',
        ws: true,
        changeOrigin: true,
        pathRewrite:{
            '^/service/rest':''
        }
    }
  }

其中 ,将changeOrigin设置为true,就不会存在无法跨域请求的问题了。

然后就可以直接在下面引用axios调用了。

代码语言:javascript
复制
import axios from '@/api/api';
export default {
    userList(params) {
        return axios.post('service/rest/api/user/logincode', params);
    },
  
};
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019-08-12 ,如有侵权请联系 cloudcommunity@tencent.com 删除
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档