实战08-NavList

import { INavItem, INavList } from '../../api/models/HomeData';

@Component
export default struct NavList {
  @Prop navList: INavList

  build() {
    Grid() {
      ForEach(this.navList, (nav: INavItem) => {
        GridItem() {
          Column({ space: 8 }) {
            Image(nav.imageURL)
              .width(58)
              .height(56)
            Text(nav.title).fontSize(12).fontColor($r('app.color.black'))
          }
        }
      }, (nav: INavItem) => nav.id + '')
    }
    .width('100%')
    .height(170)
    .rowsTemplate('1fr 1fr') //两行
    .columnsTemplate('1fr 1fr 1fr 1fr') //4列
    .rowsGap(14) //行间距
    .columnsGap(32) //列间距
    .margin({ top: 24 })
  }
}
import { getHomeDataApi } from '../api/home';
import { BannerListDataSource, INavList } from '../api/models/HomeData';
import SwiperLayout from '../views/Home/SwiperLayout';
import { window } from '@kit.ArkUI';
import SearchBar from '../views/Home/SearchBar';
import NavList from '../views/Home/NavList';
import { PADDING } from '../constants/size';


@Entry
@Component
export default struct Home {
  @State bannerList: BannerListDataSource = new BannerListDataSource()
  @State navList: INavList = []
  //获取首页数据的函数
  getHomeData = async () => {
    const result = await getHomeDataApi()
    this.bannerList.setList(result.bannerList)
    this.navList = result.navList;


  }

  //生命周期函数:初始化渲染时候
  aboutToAppear(): void {
    this.getHomeData()

    window.getLastWindow(getContext())
      .then(win => {
        win.setWindowLayoutFullScreen(true)
      })
  }

  build() {

    Scroll() {
      Stack() {
        Column() {
          //轮播图组件
          SwiperLayout({ bannerList: this.bannerList })
          Column() {
            //导航栏
            NavList({ navList: this.navList })
          }.width('100%').padding({ left: PADDING, right: PADDING })
        }.width('100%')

        //搜索区
        SearchBar()
      }.width('100%').alignContent(Alignment.TopStart)
    }
    .width('100%')
    .height('100%')
    .scrollBar(BarState.Off)
    .align(Alignment.TopStart)
    .backgroundColor('#ff73b562')

  }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值