vue-music-player icon indicating copy to clipboard operation
vue-music-player copied to clipboard

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

Open gzyhelloworld opened this issue 8 years ago • 2 comments

在网上看了一下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在这个项目怎么访问接口

gzyhelloworld avatar Apr 20 '17 08:04 gzyhelloworld

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

microzz avatar Apr 20 '17 08:04 microzz

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

hw1995 avatar Nov 01 '17 05:11 hw1995