naive-ui-admin跨域失败

周承天
2023-12-01
  1. 在使用naive-ui-admin的时候,发现无法跨域,其实已经跨域了,指示我写的后端有点问题

.env.development 

# 跨域代理,可以配置多个,请注意不要换行

#VITE_PROXY = [["/appApi","http://localhost:8001"],["/upload","http://localhost:8001/upload"]]

# VITE_PROXY=[["/api","https://naive-ui-admin"]]

# VITE_PROXY=[["/api","https://www.fastmock.site/mock/bf1fcb3c2e2945669c2c8d0ecb8009b8/api"]]

VITE_PROXY=[["/api","http://192.168.1.31:8080"]]

这里跨域

export function login(params) {

  return http.request<BasicResponseModel>(

    {

      url: '/login',

      method: 'POST',

      params,

    },

    {

      isTransformResponse: false,

    }

  );

}

指示他的login传递的params在body中,而不是queryparam,因此还是显示没有跨域成功

 @PostMapping("/login")

    public ResultData login(@RequestBody String username,String password){

        Map map = new HashMap();

        map.put("token","sdfsdfsdf");

        return new ResultData(map);

    }

    @PostMapping("/login2")

    public ResultData login2(@RequestParam("username")String username,@RequestParam("password")String password ){

        Map map = new HashMap();

        map.put("token","sdfsdfsdf");

        return new ResultData(map);

    }

 类似资料: