博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Umi-Dva配置代理,解决跨域问题

Posted on 2022-04-27 16:44  yqphare  阅读(349)  评论(0编辑  收藏  举报
proxy: {
    '/api': {
      'target': 'https://public-api-v1.aspirantzhang.com',
      'changeOrigin': true,
      'pathRewrite': { '^/api' : '' },
    },
  },

 

在umirc.ts中进行设置!

在对应的service.ts文件中,修改对应api即可

import { response } from "@umijs/deps/compiled/express";
import { request } from "umi"
export const getRemoteList =async params => {
    return request('/api/users',{
        method:'get',
        
    }).then(function(response){
        return response
        
    })
    .catch(function(error){
        console.log(error);
    })
    
      
}