Vue前后端不同端口的实现方法

作者:Simpleelegant 时间:2024-05-28 16:03:44 

前端Vue 8080端口,后端Node.js 8085端口 主要记录下前后端不同端口遇到的问题

1、写服务器端程序,我的在(node_proxy/index.js)下


app.all('*', function (req, res, next) {
res.header('Access-Control-Allow-Origin', req.headers.origin || '*');
res.header('Access-Control-Allow-Headers', 'Content-Type,Content-Length, Authorization,\'Origin\',Accept,X-Requested-With');
res.header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
res.header('Access-Control-Allow-Credentials', true);
res.header('X-Powered-By', ' 3.2.1');
res.header('Content-Type', 'application/json;charset=utf-8');
if (req.method === 'OPTIONS') {
res.sendStatus(200);
} else {
next();
}
});

这段代码很重要,要是没有的话会出现 No 'Access-Control-Allow-Origin' header is present on the requested resource 错误。

2、在前端用axios写get请求处理程序,写在了Card模板下


mounted(){
axios.get(HOST)
.then(response => {
this.sed = response.data.data;
})
}

3、在config/index.js下配置proxyTable:


proxyTable: {
'/seller': {
target: 'http://localhost:8085',
changeOrigin: true,
pathRewrite: {
 '^/seller': '/seller'
}
}
},

4、分别启动前后端,OK~\(≧▽≦)/~啦啦啦~

来源:https://blog.csdn.net/simpleelegant/article/details/78863448

标签:Vue,端口
0
投稿

猜你喜欢

  • Python数据结构之栈详解

    2021-01-07 01:12:36
  • python实现点对点聊天程序

    2023-10-27 11:42:02
  • Python pandas库中isnull函数使用方法

    2023-11-21 06:44:12
  • Python自动化办公之群发邮件案例详解

    2023-09-08 17:10:36
  • Python运算符优先级详细整理

    2021-12-17 06:38:14
  • SQL Server重温 事务

    2012-08-21 10:48:15
  • html网页颜色表大全(苏昱)

    2008-01-01 15:52:00
  • python使用插值法画出平滑曲线

    2021-07-14 03:59:02
  • python实现简单ftp客户端的方法

    2023-12-14 20:07:31
  • Python 开发工具PyCharm安装教程图文详解(新手必看)

    2023-04-25 05:01:08
  • 回顾Javascript React基础

    2023-07-13 00:57:00
  • Java读取文件及基于正则表达式的获取电话号码功能详解

    2022-06-18 09:11:45
  • python连接mysql有哪些方法

    2024-01-21 11:23:11
  • SQL Select语句完整的执行顺序

    2008-09-28 21:22:00
  • 解决pandas .to_excel不覆盖已有sheet的问题

    2022-12-02 22:42:25
  • kali添加开机自启的方法

    2023-06-06 04:15:06
  • python 3利用Dlib 19.7实现摄像头人脸检测特征点标定

    2022-07-31 05:54:21
  • 详细解读php的命名空间(一)

    2023-06-19 08:02:59
  • Python3 sys.argv[ ]用法详解

    2021-08-03 00:16:29
  • Javascript图像处理—图像形态学(膨胀与腐蚀)

    2024-04-23 09:27:58
  • asp之家 网络编程 m.aspxhome.com