首先在Vue-CLI根目录下创建一个名为 vue.config.js 的js文件
在vue.config.js中文件的配置如下:
module.exports = {
publicPath: "/",
devServer: {
proxy: {
"/api": {
// 代理名称 凡是使用/api开头的地址都是用此代理
target: "http://localhost:4000/", // 需要代理访问的api地址
changeOrigin: true, // 允许跨域请求
pathRewrite: {
// 重写路径,替换请求地址中的指定路径
"^/api": "/", // 将请求地址中的/api替换为空,也就是请求地址中不会包含/api/
},
},
},
},
};