后端返回结构👇
export interface ApiResult<T> {
code: number;
msg: string;
result: T;
}
T 里面放后端的数据结构基类
然后 T 类的 Extend 的类中定义构造器参数为 T 类
进行实例化就可以了
前端基于后端的 T 类 进行 extends 的结构( Contact 类就是我 Group 类用到的基类,也就是后台返回的 T 类型)👇
export class Group extends Contact {
public upperlimit: number;
public creater: string;
public announcement: string;
constructor(baseGroup: BaseGroup) {
super({
key: baseGroup.id.toString(),
name:
baseGroup.name,
imgSrc: baseGroup.logo
});
this.creater = baseGroup.createUserID.toString();
this.upperlimit = baseGroup.grade;
this.announcement = baseGroup.description;
}
}