vue.config.js 页面代码
devServer: {
port: 8081,
host: 'localhost',
open: true,
https: false,
proxy: {
'/api': {
target: 'https://xxx.com/', // 真实后台域名
ws: true,
changeOrigin: true, // 在这里设置是否跨域
pathRewrite: { // 重定向
'^/api': ''
}
}
}
}
main.js 页面代码
axios.defaults.baseURL = '/api/'