Vite 跨域问题中vite.config.ts的配置
问题描述:
Access to XMLHttpRequest at ‘http://lxxx:9407/login‘ from origin ‘http://localhost:8888‘ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.
只需要配置vite.config.ts中的server-proxy选项。
代码如下:
1 | import { defineConfig } from 'vite' |
使用:
1 | const httpClinet = axios.create({ |
baseURL处使用/api来代替原来的链接路径就好了。
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 七宝的小窝!
评论
匿名评论
你无需删除空行,直接评论以获取最佳展示效果