鸿蒙代码备份

 0720-13:03

Index.ets

import article from '../pages/article'
import http from '@ohos.net.http';
import HttpTools from './tools/HttpTools';
@Entry
@Component

struct Index
{
  @State arr:article[]=
    [new article(1,"房东的猫","wechat",10240,5870,4396,"2024-7-19","微信小程序",false),
    new article(2,"什码情况","vue",9785,4396,2200,"2024-7-19","todolist",false),
    new article(3,"L世界凌乱了","javascript",8888,7777,6666,"2024-7-20","原型",false)]

  build()
  {
    Column()
    {
      Row()
      {
        Text("推荐").fontSize(25)
        Text("热榜").fontSize(25)
        Button("十",{type:ButtonType.Normal}).
        onClick((event: ClickEvent) =>
        {

        })
      }.justifyContent(FlexAlign.SpaceBetween)
      .width("100%")
      //.margin({top:50})

      List({ space: 10, initialIndex: 0 })
      {
        ForEach(this.arr, (item) =>
        {
          ListItem()
          {
            Column()
            {
              Text(item.name).margin({right:250}).fontSize(18)
              Text(item.title)
                .width("100%")
                .margin({top:20,left:0,bottom:100})
                .fontSize(25)
                .fontWeight(800)

              Row()
              {
                Text(item.viewcounts.toString() + "阅读").fontSize(14)
                Text(" | ").fontSize(14)
                Text(item.like.toString() + "喜欢").fontSize(14)
                Text(" | ").fontSize(14)
                Text(item.collect.toString() + "收藏").fontSize(14)
              }
              .width("100%")
              .justifyContent(FlexAlign.Start)

            }.width("100%")
          }.height(180)
        }, item => item.id)
      }
      .listDirection(Axis.Vertical) // 排列方向
      .divider({ strokeWidth: 7, color:('#ffcfcfcb'), startMargin: 0, endMargin: 0 }) // 每行之间的分界线
      .edgeEffect(EdgeEffect.Spring) // 滑动到边缘无效果
      .onScrollIndex((firstIndex: number, lastIndex: number) =>
      {
        console.info('first' + firstIndex)
        console.info('last' + lastIndex)
      })
      .width('90%')
    }.backgroundColor('#fffff97')
  }

  login()
  {
    // 每一个httpRequest对应一个HTTP请求任务,不可复用
    let httpRequest = http.createHttp();
    let url = ''
    let options :http.HttpRequestOptions =
      {
        method: http.RequestMethod.POST, // 可选,默认为http.RequestMethod.GET
        // 开发者根据自身业务需要添加header字段
        header:
        {
          'Content-Type': 'application/json'
        },
        // 当使用POST请求时此字段用于传递内容
        extraData:
        {
          "data": this.arr,
        },
      }

    HttpTools.get(url,(result)=>{

    })

    httpRequest.request(url,options, (err, data) =>
    {
      if (!err)
      {
        // data.result为HTTP响应内容,可根据业务需要进行解析
        console.info('Result:' + JSON.stringify(data.result));
        console.info('code:' + JSON.stringify(data.responseCode));
        // data.header为HTTP响应头,可根据业务需要进行解析
        console.info('header:' + JSON.stringify(data.header));
        console.info('cookies:' + JSON.stringify(data.cookies)); // 8+
        // 取消订阅HTTP响应头事件
        httpRequest.off('headersReceive');
        // 当该请求使用完毕时,调用destroy方法主动销毁
        httpRequest.destroy();
      }
      else
      {
        console.info('error:' + JSON.stringify(err));
        // 取消订阅HTTP响应头事件
        httpRequest.off('headersReceive');
        // 当该请求使用完毕时,调用destroy方法主动销毁。
        httpRequest.destroy();
      }
    })
  }
}

HttpTools.ets

export default class HttpTools
{
  static get(url:string,fn:Function)
  {

  }
}

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值