tab2.page.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import { Component } from '@angular/core';
  2. @Component({
  3. selector: 'app-tab2',
  4. templateUrl: 'tab2.page.html',
  5. styleUrls: ['tab2.page.scss'],
  6. })
  7. export class Tab2Page {
  8. public items: any[] = [
  9. { title: '鬼吹灯', author: '天下霸唱', coverUrl: 'assets/1.jpg', status: '连载' },
  10. { title: '逆天', author: 'duck', coverUrl: 'https://img.zcool.cn/community/01b3cf5d65b03da80120695c80f433.jpg@1280w_1l_2o_100sh.jpg', status: '完结' },
  11. { title: '我在末世学os', author: '桀桀桀', coverUrl: 'https://ts1.cn.mm.bing.net/th/id/R-C.886e302b920108dbdda410492ad3305c?rik=36F0OuXWXFcmPQ&riu=http%3a%2f%2fwww.tup.com.cn%2fupload%2fbigbookimg3%2f047449-01.jpg&ehk=huHr4ZFPELtGAO7zbtoiYnnOHSdwAtyFysDp245Dqno%3d&risl=&pid=ImgRaw&r=0', status: '连载' },
  12. { title: '我在末世学高数', author: '我欲封天', coverUrl: 'https://img.alicdn.com/bao/uploaded/O1CN01cSGVcE1SKvbRW3cHd_!!6000000002229-0-yinhe.jpg', status: '连载' },
  13. // 可以根据需要添加更多的书籍数据,确保每本书籍都有一个 status 属性表示完结或连载
  14. ];
  15. public filteredItems: any[];
  16. public currentCategory: string = '全部';
  17. constructor() {
  18. // 初始时展示全部书籍
  19. this.filteredItems = this.items;
  20. }
  21. changeCategory(category: string) {
  22. this.currentCategory = category;
  23. if (category === '全部') {
  24. this.filteredItems = this.items;
  25. } else {
  26. this.filteredItems = this.items.filter(item => item.status === category);
  27. }
  28. }
  29. }