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、


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM