Vue的跨域问题可以使用代理的方式解决,在项目config文件夹中的index.js中配置proxyTable选项。

config > index.js

1. dev: {
2.     env: require('./dev.env'),
3.     port: 8080,
4.     autoOpenBrowser: true,
5.     assetsSubDirectory: 'static',
6.     assetsPublicPath: '/',
7.     proxyTable: {
8.       '/api': {
9.         target: 'http://open.douyucdn.cn/api/RoomApi',
10.         changeOrigin: true,
11.         pathRewrite: {
12.          '^/api': ''
13.         }
14.        }
15.     },
16.     // CSS Sourcemaps off by default because relative paths are "buggy"
17.     // with this option, according to the CSS-Loader README
18.     // (https://github.com/webpack/css-loader#sourcemaps)
19.     // In our experience, they generally work as expected,
20.     // just be aware of this issue when enabling this option.
21.     cssSourceMap: false
22.   }

在项目中使用 vue-resource 发起请求

1. this.$http.get('/api').then((response)=>{
2.   // 响应成功回调
3.   console.log(response);
4. },(error)=>{
5.   // 响应错误回调
6.   console.log(error);
7. })