当前位置:网站首页>跨域问题的解决方法
跨域问题的解决方法
2022-07-30 18:44:00 【二脸懵逼】
方法一:1、使用的是node.js搭建的后台
app.all('*', function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
res.header("X-Powered-By",' 3.2.1')
res.header("Content-Type", "application/json;charset=utf-8");
next();
});
2、使用vue,设置代理
在vue.config.js中编写如下代码:
//跨域设置
module.exports = {
devServer: {//开发环境的服务
proxy: {//代理设置
'/api': {
target: '请求地址',
changeOrigin: true,//是否跨域
pathRewrite: {//路径重写
'^/api': ''//^/api以/api开头
}
}
}
},
}
边栏推荐
- MYSQL(基本篇)——一篇文章带你走进MYSQL的奇妙世界
- Presto 中 lookUp Join的实现
- Mysql execution principle analysis
- while,do while,for循环语句
- C# wpf borderless window add shadow effect
- ESP8266-Arduino编程实例-HC-SR04超声波传感器驱动
- Network Basics (3) 01-Basic Concepts of Networks - Protocols, Host Addresses, Paths and Parameters of URL Addresses & 127.0.0.1 Local Loopback Address & View URL IP Address and Access Ping Space + URL
- 单例模式 (Singleton)
- 延时队列优化 (2)
- Common linked list problems and their Go implementation
猜你喜欢
Delay queue optimization (2)
AI基础:图解Transformer
WeChat Mini Program Cloud Development | Urban Information Management
微信小程序云开发 | 城市信息管理
Hello, my new name is "Bronze Lock/Tongsuo"
你好,我的新名字叫“铜锁/Tongsuo”
OneFlow source code analysis: Op, Kernel and interpreter
Codeblocks + Widgets 创建窗口代码分析
Immersive experience iFLYTEK 2022 Consumer Expo "Official Designated Product"
SwiftUI iOS Boutique Open Source Project Complete Baked Food Recipe App based on SQLite (tutorial including source code)
随机推荐
The sixteenth issue of eight-part article Balabala said (MQ)
深化校企合作 搭建技术技能人才成长“立交桥”
自己需要努力
【剑指 Offe】剑指 Offer 17. 打印从1到最大的n位数
常见链表题及其 Go 实现
After 23 years of operation, the former "China's largest e-commerce website" has turned yellow...
C# wpf 无边框窗口添加阴影效果
Node encapsulates a console progress bar plugin
Critical Reviews | A review of the global distribution of antibiotics and resistance genes in farmland soil by Nannong Zou Jianwen's group
requet.getHeader("token") is null
CCNA-网络汇总 超网(CIDR) 路由最长掩码匹配
【Prometheus】Prometheus联邦的一次优化记录[续]
Chapter 4 Controlling the Execution Flow
开心的聚餐
kotlin by lazy
载誉而归,重磅发布!润和软件亮相2022开放原子全球开源峰会
MYSQL(基本篇)——一篇文章带你走进MYSQL的奇妙世界
CCNA-子网划分(VLSM)
The Meta metaverse division lost 2.8 billion in the second quarter!Still want to keep betting?Metaverse development has yet to see a way out!
Recommendation | People who are kind to you, don't repay them by inviting them to eat