Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vue.axios 的具体是怎么实现的 #7

Open
gzyhelloworld opened this issue Apr 20, 2017 · 2 comments
Open

Vue.axios 的具体是怎么实现的 #7

gzyhelloworld opened this issue Apr 20, 2017 · 2 comments

Comments

@gzyhelloworld
Copy link

在网上看了一下Vue.axios教程,为什么this.axios.get('/api/hot')就可以获得返回,不用设置baseURL吗?

this.axios.defaults.baseURL = 'http://music.qq.com/musicbox/shop/v3/data/hit';
this.axios.get('/hit_newsong.js')
.then(function (response) {
  console.log(response);
})
.catch(function (error) {
  console.log(error);
});

没看懂axios,写了一下,可以获得返回但是提示存在跨域问题。不懂axios在这个项目怎么访问接口

@microzz
Copy link
Owner

microzz commented Apr 20, 2017

@gzyhelloworld 你好,前端页面直接请求QQ音乐接口是会有跨域限制的,所以我在后端Express(自己上线版本是Koa2)里面做了一个代理一样,由后端去请求那些api,然后返回给前端页面,代码部分在https://github.com/microzz/vue-music-player/blob/2.0.0/build/dev-server.js 这个文件内😄

@hw1995
Copy link

hw1995 commented Nov 1, 2017

这是vue-cli搭建的项目中会有一个地方专门写代理

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants