vue-resource跨域问题

今天在项目中使用vue-resource的时候,我的vue项目开发地址是http://localhost:8080/set,但是我想获取http://localhost:80/ 域名下的数据,于是遇到了跨域问题:
这里写图片描述
我在使用vue-resource请求数据的时候是这样写的

this.$http.get('http://localhost:80/picasso-wan/governance-api/v1/sys_score_sheets/part_query')
.then((res) => {
 console.log(res)
}, (err) => {
  console.log(err)
});

很明显,跨域了。于是我百度各种关于vue-resource中的跨域问题的解决方法,后来,在项目config目录下的index.js文件中的”dev”下,添加下面的代码,并改变使用的路径。
这里写图片描述

target中写你想要请求数据的地址的域名,然后在使用时改成this.$http.get('/api/picasso-wan/governance-api/v1/sys_score_sheets/part_query') ,然后重新npm run dev ,可发现数据已获取成功。
这里写图片描述

这篇文章主要是记录我在使用vure-resource时遇到跨域问题的解决方法,仅供参考!

猜你喜欢

转载自blog.csdn.net/qq_33036599/article/details/80313138