关于慕课网避开icode验证的方法一(本地部署与线上部署)

关于本地部署,设置proxy避开icode验证:

    例如vue项目,,在vue.config.js(项目初建时没有vue.config.js文件,需自己手动建立该文件如图)

     在vue.config.js中设置proxy:

module.exports = { 
    devServer: { 
    overlay: { 
    warnings: true, 
    errors: true 
    }, 
    host: 'localhost', 
    port: 8080, 
    https: false, 
    open: true, 
    hotOnly: true, 
    proxy: { 
    '/api': { 
    target: 'http://xxxxxxxxxx',//跨域接口的地址 
    changeOrigin: true, 
    pathRewrite: { 
    '^/api': '' 
    } 
    } 
    }, 
    headers: { 
    'Access-Control-Allow-Origin': '*', 
    } 
    } 
    }; 

    在原老师设置的地方只需要将默认访问地址设置为‘/api’,即可进行跨域代理。

 线上部署请看下一页。

原文地址:https://www.cnblogs.com/jundongsheng/p/14580610.html