Skip to content

Instantly share code, notes, and snippets.

@itwondersteam
Created February 25, 2021 13:46
Show Gist options
  • Select an option

  • Save itwondersteam/3a2c502436190e673c3fd2ffdb0d313f to your computer and use it in GitHub Desktop.

Select an option

Save itwondersteam/3a2c502436190e673c3fd2ffdb0d313f to your computer and use it in GitHub Desktop.
export interface IUser {
id?: number;
email: string;
first_name: string;
last_name: string;
avatar: string;
}
export class UserDTO implements IUser{
id?: number;
avatar: string = '';
email: string = '';
first_name: string = '';
last_name: string = '';
}
export default class User extends UserDTO {
constructor(dto: UserDTO){
super();
Object.assign(this, dto);
}
get fullName(): string {
return `${this.first_name} ${this.last_name}`;
}
}
/// User.ts
@itwondersteam
Copy link
Author

static async getAllUsers(): Promise<User[]>{
  let url = 'https://reqres.in/api/users'
  let response = await this.usersAxios.get<RequestInterface>(url);
  return response.data.data.map(userDto => new User(userDto));
}

@itwondersteam
Copy link
Author

<v-list-item :key="index" v-for="(user, index) in users">
  {{user.fullName}}
</v-list-item>
/// HomeComponent.vue - html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment