node脚手架下Vue2从前端代码解决跨域问题
解决办法
vue.config.js
module.exports = defineConfig({
devServer: {
proxy: {
'/cross-domain': {
target: '你要访问的目标服务器domain',
changeOrigin: true,
pathRewrite: {
'^/cross-domain': ''
}
}
}
},
}
注意:用该方法解决跨域,axios.defaults.baseURL就不要再设置目标服务器domain