1.添加代理
vue.config.js
devServer: {
// 配置服务器代理
proxy: {
"/apis": { // 代理接口前缀为/api的请求
"target": 'http://xxxx:3000', // 目标请求地址
"secure": false, // 接受运行在https上,默认不接受
"changeOrigin": true, // 如果设置为true
"pathRewrite": { //重写路径
'^/apis': ''
}
},
// 配置多个代理
"/service": {
"target": 'https://www.google.com/',
"secure": false,
"changeOrigin": true,
},
}
}
2.axios修改路径
const instance = axios.create({
baseURL: '/apis',
timeout: 10000,
withCredentials: true,
})