關於本地部署,設置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’,即可進行跨域代理。
線上部署請看下一頁。