vue项目中跨域问题的解决
1、当跨域无法请求的时候我们可以修改工程下config文件夹下的index.js中的dev:{}部分。代码如下:主要修改的是
proxyTable:{}内部的内容
dev: { env: require('./dev.env'), port: 8080, autoOpenBrowser: true, assetsSubDirectory: 'static', assetsPublicPath: '/', proxyTable: { '/api/**': { target: 'http://api.douban.com/v2', //表示你跨域请求的接口的域名 secure: false, //如果是https接口,需要配置这个参数 changeOrigin: true, //如果接口跨域,需要进行这个参数配置 }, '/users/*': { target: 'http://127.0.0.1:8089' } }, // CSS Sourcemaps off by default because relative paths are "buggy" // with this option, according to the CSS-Loader README // (https://github.com/webpack/css-loader#sourcemaps) // In our experience, they generally work as expected, // just be aware of this issue when enabling this option. cssSourceMap: false }
2、