vue.config.js 代码:
devServer: {
proxy: { // 配置跨域
'/NewService': {
target: `http://192.168.0.254:9007`, //请求后台接口
changeOrigin: true, // 允许跨域
// pathRewrite: {
// '^/NewService': '/' // 重写请求
// }
},
},
}
在封装axios时要加上:
axios.defaults.baseURL = '/NewService'
(切记不要写成这样)
axios.defaults.baseURL = 'http://192.168.0.254:9007/NewService'