当前位置:网站首页>vite配置proxy代理解决跨域
vite配置proxy代理解决跨域
2022-04-23 17:41:00 【Suk_阿硕】
上代码:
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import { resolve } from 'path';
// https://vitejs.dev/config/
export default defineConfig({
server: {
port: 9090,
strictPort: true, // 严格端口 true:如果端口已被使用,则直接退出,而不会再进行后续端口的尝试。
/**
* @description 解决chrome设置origin:*也跨域机制,代理/api前缀到服务基地址
* 最终的地址会将axios设置的baseUrl:/api代理拼接成[target][/api],然后通过rewrite重写掉/api为'' 这样就是我们真实的基地址了
*/
proxy: {
'/api': {
target: 'http://www.baidu.com', // 接口基地址
rewrite: path => {
console.log(path); // 打印[/api/userInfo] 这就是http-proxy要请求的url,我们基地址实际是没有/api 所以replace掉
return path.replace(/^\/api/, '');
}
}
}
},
plugins: [vue()],
resolve: {
alias: {
'@': resolve(__dirname, '.', 'src') // 设置 @ 指向 src
}
},
})
版权声明
本文为[Suk_阿硕]所创,转载请带上原文链接,感谢
https://blog.csdn.net/Suk__/article/details/124310263
边栏推荐
- For the space occupation of the software, please refer to the installation directory
- Future usage details
- Future 用法详解
- MySQL进阶学习之SQL优化【插入,主键,排序,分组,分页,计数】
- SystemVerilog(六)-变量
- Some questions some questions some questions some questions
- 双指针进阶--leetcode题目--盛最多水的容器
- PC uses wireless network card to connect to mobile phone hotspot. Why can't you surf the Internet
- 超分之TDAN
- Oninput one function to control multiple oninputs (take the contents of this input box as parameters) [very practical, very practical]
猜你喜欢

2.Electron之HelloWorld
![MySQL advanced index [classification, performance analysis, use, design principles]](/img/96/b031868602a7b8ba4edd0d74c843b3.png)
MySQL advanced index [classification, performance analysis, use, design principles]

JVM class loading mechanism

.Net Core3. 1 use razorengine NETCORE production entity generator (MVC web version)

双闭环直流调速系统matlab/simulink仿真

394. 字符串解码-辅助栈

Index: teach you index from zero basis to proficient use

土地覆盖/利用数据产品下载

Double pointer advanced -- leetcode title -- container with the most water
![[difference between Oracle and MySQL]](/img/90/6d030a35692fa27f1a7c63985af06f.png)
[difference between Oracle and MySQL]
随机推荐
402. 移掉 K 位数字-贪心
练习:求偶数和、阈值分割和求差( list 对象的两个基础小题)
matlab如何绘制已知公式的曲线图,Excel怎么绘制函数曲线图像?
31. Next arrangement
Using quartz under. Net core -- operation transfer parameters of [3] operation and trigger
[logical fallacy in life] Scarecrow fallacy and inability to refute are not proof
双闭环直流调速系统matlab/simulink仿真
48. Rotate image
Manually implement call, apply and bind functions
.Net Core3. 1 use razorengine NETCORE production entity generator (MVC web version)
为什么有些人说单片机简单,我学起来这么吃力?
SystemVerilog(六)-变量
MySQL进阶学习之SQL优化【插入,主键,排序,分组,分页,计数】
Clickhouse table engine
1217_使用SCons生成目标文件
Using quartz under. Net core -- preliminary understanding of [2] operations and triggers
Exercise: even sum, threshold segmentation and difference (two basic questions of list object)
Compare the performance of query based on the number of paging data that meet the query conditions
Change Oracle to MySQL
Model problems of stock in and stock out and inventory system