当前位置:   article > 正文

vite多个跨域配置_vite配置多个跨域

vite配置多个跨域
  1. proxy: {
  2. '/api': {
  3. target: 'xxxx', //目标url
  4. changeOrigin: true, //支持跨域
  5. rewrite: (path) => path.replace(/^\/api/, ''),
  6. //重写路径,替换/api
  7. },
  8. '/plant': {
  9. target: 'xxxx', //目标url
  10. changeOrigin: true, //支持跨域
  11. rewrite: (path) => path.replace(/^\/plant/, ''),
  12. },
  13. },

开发环境

  1. # base api
  2. VITE_BASE_API = ''

api

  1. import request from '@/utils/http'
  2. export function fetchList(query) {
  3. return request({
  4. // /plant是跨域的前名
  5. url: '/plant/xxx',
  6. method: 'get',
  7. params: query,
  8. })
  9. }

axios的基地址

  1. const service = axios.create({
  2. baseURL: import.meta.env.VITE_BASE_API, // 设置axios请求的基础的基础地址
  3. timeout: 30000, // 定义5秒超时
  4. withCredentials: true,
  5. })
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/598086
推荐阅读
  

闽ICP备14008679号