当前位置:网站首页>跨域问题的解决方法
跨域问题的解决方法
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开头
}
}
}
},
}
边栏推荐
猜你喜欢

Node encapsulates a console progress bar plugin

DTSE Tech Talk丨第2期:1小时深度解读SaaS应用系统设计

SwiftUI iOS Boutique Open Source Project Complete Baked Food Recipe App based on SQLite (tutorial including source code)

微信小程序云开发 | 城市信息管理

kotlin的by lazy

Read the "Language Model" in one article

NC | Tao Liang Group of West Lake University - TMPRSS2 "assists" virus infection and mediates the host invasion of Clostridium sothrix hemorrhagic toxin...

Scrapy框架介绍

6块钱1斤,日本公司为何来中国收烟头?

CCNA-NAT协议(理论与实验练习)
随机推荐
生物医学论文有何价值 论文中译英怎样翻译效果好
Mysql执行原理剖析
荐号 | 对你有恩的人,不要请吃饭来报答
OneFlow source code analysis: Op, Kernel and interpreter
OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized.解决方法
Does the satellite phone communicate directly with the satellite or through a ground station?
Anaconda Navigator卡在loading applications
kotlin的by lazy
【Qt Designer工具的使用】
LocalDate时间生成
OSPF详解(4)
第十六期八股文巴拉巴拉说(MQ篇)
Chapter 4 Controlling the Execution Flow
攻防世界web-Cat
NC | Tao Liang Group of West Lake University - TMPRSS2 "assists" virus infection and mediates the host invasion of Clostridium sothrix hemorrhagic toxin...
【PHPWord】Quick Start of PHPWord in PHPOffice Suite
ESP8266-Arduino编程实例-HC-SR04超声波传感器驱动
Fixed asset visualization intelligent management system
使用postman调接口报Content type ‘text/plain;charset=UTF-8‘ not supported
"Ruffian Heng Embedded Bimonthly" Issue 59