在项目根目录下的 vue.config.js 文件中(如果没有,就增加一个这样的文件)配置代理,代码如下:
module.exports = {
devServer: {
proxy: {
'/api': {
target: 'http://localhost:4000',
ws: true,
changeOrigin: true,
pathRewrite: {
'^/api': ''
}
}
}
}
}
以上的配置是所有的请求都以 /api 开头,所以需要配置请求的基础地址
const instence = axios.create({
baseURL: '/api',
})
配好之后记得重启项目
转载请注明原文地址:https://ipadbbs.8miu.com/read-48959.html