组件得编写

奇迹不会泯灭 / 2023-05-22 / 原文

一个组件需要请求远程得参数,暴露出对应得promise函数

export type ProductList = {
  total: number;
  list:Array<{
    id:string;
    name:string;
  }>
}
export type RequestData = {
  pageInfo:{currentPage:number,pageSize:number},
  searchParams:{name:string,id:string}
}
export type AsyncProductList = ( pageInfo:{currentPage:number,pageSize:number},searchParams:{name:string,id:string})=>Promise<ProductList>
export type IComponentsProps = {
  //the service to get product list
  loadProduct: AsyncProductList
}
export function test111(data:RequestData){
  return Axios<ProductList>({
    url: `api/xxx`,
    method: 'get',
    ...data,
  })
}