vue.js - vue-resource调接口有同源问题?

查看:148
本文介绍了vue.js - vue-resource调接口有同源问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

vm.$http.post('http://XXX/employee/GetEmployeeList',formData).then((response) => {
        if(response.body.errmsg == 'sucess'){
          _this.employees = response.body.data
          console.log(_this.employees);
        }
      })

报错

 No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.

解决方案

vue-resource 只是提供http请求简便方法,跨域这种,要么接口支持跨域,要么接口支持jsonp,如果你只是用的vue2和vue-cli,仅仅只是本地开发下跨域不方便的话,不妨试试 config目录下的index.js里的proxyTable

http://www.jianshu.com/p/95b2...

如果不是我说的情况- -忽略我的回答= =||

这篇关于vue.js - vue-resource调接口有同源问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆