vue代理不生效,本地的node接口,vue项目配置了代理,结果还是跨域
// vue代理
devServer: {
port: 3001,
proxy: {
"/api": {
target: "http://localhost:3000",
changeOrigin: true,
},
},
},
// 访问接口
async getData() {
let res = await axios.get("http://127.0.0.1:3000/api/liyfn");
console.log(res);
},
// node服务
app.get("/api/liyfn", (req, res) => {
console.log(
"请求来了",
req.url,
req.socket.remoteAddress,
req.socket.remotePort
);
res.send({
status: 200,
msg: "请求成功",
data: "liyfn",
});
});
let server = app.listen("3000", () => {
console.log("已开启服务");
});
结果代理没有生效,还是跨域了