本文介绍: vue3中几种封装让后端传参请求方式post请求,但是后端参数不是对象,是一个单参

1、post请求,但是后端参数不是对象,是一个单参

后端

        /// <summary>
        /// 获取项目服务详情
        /// </summary>
        /// <param name=”id”></param>
        /// <returns></returns>
        /// <exception cref=”UserFriendlyException”></exception>
        [AllowAnonymous]
        [HttpPost(“get-eploymentDetails”)]
        public async Task<GetProjectDetailsDto> GetDetailsAsync(Guid id)
        {
            return await _projectServiceAppService.GetDetailsAsync(id);
        }

前端使用如下,是错误的,传参传不过去

// 获取就业服务详情

export function getDetail(id) {

  return request({

    url: “/api/SupplyDemand/employmentService/get-eploymentDetails”,

    method: “post”,

    data: { id },

  });

}

 需使用如下形式:

//获取项目服务详情

export function getDetail(id) {

    return request({

      url: “/api/SupplyDemand/projectService/get-eploymentDetails”,

      method: “post”,

      params: { id },

    });

}

2、get请求

后端

        /// <summary>
        /// 项目专题列表
        /// </summary>
        /// <param name=”count”>显示条数</param>
        /// <returns></returns>
        [HttpGet(“get-projectList”)]
        [AllowAnonymous]
        public async Task<List<GetProjectListDto>> GetProjectListAsync(int count)
        {
            return await _projectServiceAppService.GetProjectListAsync(count);
        }

前端

//项目服务列表

export function getProjectList(count){

    return request.get(

        `/api/SupplyDemand/projectService/get-projectList?count=${count}`

    );

}

3、post请求,后端定义的一个对象参数

        /// <summary>
        /// 创建或更新项目服务
        /// </summary>
        /// <param name=”input”></param>
        /// <returns></returns>
        /// <exception cref=”BusinessException”></exception>
        [HttpPost(“create-update-project”)]
        public async Task CreateOrUpdateAsync(CreateOrUpdateProjectInput input)
        {
            await _projectServiceAppService.CreateOrUpdateAsync(input);
        }

前端

//申请项目服务咨询

export function subimtServiceApply(data){

    return request({

        url: “/api/SupplyDemand/serviceApply/carete-serviceApply”,

        method: “post”,

        data,

    });

}

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注