-
在项目根目录下新建
vue.config.js
文件,并写入以下内容module.exports = { devServer:{ // 本地域名 host:'localhost', // 本地端口 port:'8080', open:true, proxy:{ //配置跨域 // 当访问到 api 开头的接口时走下面的内容 '/api':{ // 最终想要访问的地址 target:'https://www.imooc.com', changeOrigin:true,//允许跨域 pathRewrite:{ '^/api':'' } } } } }
-
在
vue
中这样发送请求即可this.axios.get('api/common/adver-getadverlistbymarking?marking=global_newcomer').then(res => { console.log(res); })
-
最终访问的地址是
https://www.imooc.com/common/adver-getadverlistbymarking?marking=global_newcomer
vue 中配置跨域问题
于 2021-08-25 17:28:52 首次发布