当前位置: 首页 > news >正文

【每日学点HarmonyOS Next知识】网页Scheme拉起应用、列表刷新、Web下载文件、根据子元素

1、HarmonyOS 目前 app 中是否支持网页Scheme拉起应用?

支持deeplink的,网页中添加按钮引导用户拉起应用。网页端直接提示打开应用按钮绑定点击事件window.open(tzptest://www.xxxxx.com?url=XXX)>,点击该按钮,打开网页web端收到的url为tzptest://www.xxxxx.com?url=XXX

应用想被成功拉起则需要应用在工程的model.json5文件中配置abilities的skills中配置

{
  "actions": [
  "ohos.want.action.viewData"
  ],
  "uris": [
  {
    "scheme": "tzptest"
  }
  ]
}

需要注意deeplink链接的scheme协议头必须网页拉起的链接的应用配置的保持一致。另外浏览器不会对deeplink链接做任何解析或处理,只会原封不动的传递给拉起的应用。因此第三方应用只需要自己的网页端和应用端协商好url规则,自己去做解析打开对应页面即可

参考隐式want拉起应用:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/want-overview-V5

2、HarmonyOS 根据列表的title,刷新列表的数据?

可以参考以下demo实现:

@Entry
@Component
struct Index {
  @State focusIndex: number = 0;
  private controller: TabsController = new TabsController();
  tabArray = [0, 1,2,3,4,5,6,7];

  // 自定义页签
  @Builder
  Tab(tabName: string, tabItem: number, tabIndex: number) {
    Column({ space: 20 }) {
      Text(tabName).fontSize(18)
      Image($r('app.media.icon')).width(20).height(20)
    }
    .width(100)
    .height(60)
    .borderRadius({ topLeft: 10, topRight: 10 })
    .onClick(() => {
      this.controller.changeIndex(tabIndex);
      this.focusIndex = tabIndex;
    })
    .backgroundColor(tabIndex === this.focusIndex ? '#ffffffff' : '#ffb7b7b7')
  }

  build() {
    Column() {
      Column() {
        // 页签
        Row({ space: 6 }) {
          Scroll() {
            Row() {
              ForEach(this.tabArray, (item: number, index: number) => {
                this.Tab('页' + item, item, index);
              })
            }.margin({right: 80})
            .justifyContent(FlexAlign.Start)
          }
          // 设置左对齐
          .align(Alignment.Start)
          .scrollable(ScrollDirection.Horizontal)
          .scrollBar(BarState.Off)
          .width('80%')
          .backgroundColor('#ffb7b7b7')
        }
        .width('100%')
        .backgroundColor('#ffb7b7b7')

        // tabs
        Tabs({ barPosition: BarPosition.Start, controller: this.controller }) {
          ForEach(this.tabArray, (item: number, index: number) => {
            TabContent() {
              Text(' 我是页面 ' + item + ' 的内容')
                .height(300)
                .width('100%')
                .fontSize(30)
            }
            .backgroundColor(Color.Pink)
          })
        }
        .barHeight(0)
        .animationDuration(100)
        .onChange((index: number) => {
          console.log('foo change');
          this.focusIndex = index;
        })
      }
      .alignItems(HorizontalAlign.Start)
      .width('100%')
    }
    .height('100%')
  }
}
3、HarmonyOS web下载文件点击无反应?

可以把web的权限都设置为true,然后调试一下页面是否成功触发了下载,调试页面可参考使用Devtools工具调试前端页面:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/web-debugging-with-devtools-V5

Web组件支持使用DevTools工具调试前端页面。DevTools是一个 Web前端开发调试工具,提供了电脑上调试移动设备前端页面的能力。开发者通过setWebDebuggingAccess()接口开启Web组件前端页面调试能力,利用DevTools工具可以在电脑上调试移动设备上的前端网页,设备需为4.1.0及以上版本。

4、HarmonyOS ets文件如何使用any?

可以采用ESObject来替代any。但需要了解ESObject的使用场景,链接:

  • https://developer.huawei.com/consumer/cn/doc/harmonyos-faqs-V5/faqs-coding-9-V5
  • https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/typescript-to-arkts-migration-guide-V5#%E9%99%90%E5%88%B6%E4%BD%BF%E7%94%A8esobject%E7%B1%BB%E5%9E%8B
5、HarmonyOS Grid 组件如何根据子元素自适应高度?

期望Grid组件的整体高度根据其内部元素的总高度来决定,不出滚动条,请问是否能实现?(内部元素高度不确定,无法固定设置Grid总高度)

参考如下Demo:

@Entry
@Component
struct GridExample {
  @State Number: String[] = ['0', '1', '2', '3', '4','5','6','7','8','9']
  scroller: Scroller = new Scroller()
  build() {
    Column({ space: 5 }) {
      Text('scroll').fontColor(0xCCCCCC).fontSize(9).width('90%')
      Grid(this.scroller) {
        ForEach(this.Number, (day: string) => {
          ForEach(this.Number, (day: string) => {
            GridItem() {
              Text(day)
                .fontSize(16)
                .backgroundColor(0xF9CF93)
                .width('100%')
                .height(80)
                .textAlign(TextAlign.Center)
            }
          }, (day: string) => day)
        }, (day: string) => day)
      }
      .columnsTemplate('1fr 1fr 1fr 1fr 1fr')
      .columnsGap(10)
      .rowsGap(10)
      .onScrollIndex((first: number) => {
        console.info(first.toString())
      })
      .width('80%')
      .layoutDirection(GridDirection.Row)
      .maxCount(3)
      .backgroundColor(0xFAEEE0)
      .scrollBarWidth(0)
    }.width('100%').margin({ top: 5 })
  }
}
 
//在外层布局添加滚动布局scroll
@Entry
@Component
struct GridExample {
  @State Number: String[] = ['0', '1', '2', '3', '4','5','6','7','8','9']
  scroller: Scroller = new Scroller()
  build() {
    Scroll() {
      Column({ space: 5 }) {
        Text('scroll').fontColor(0xCCCCCC).fontSize(9).width('90%')
        Grid(this.scroller) {
          ForEach(this.Number, (day: string) => {
            ForEach(this.Number, (day: string) => {
              GridItem() {
                Text(day)
                  .fontSize(16)
                  .backgroundColor(0xF9CF93)
                  .width('100%')
                  .height(80)
                  .textAlign(TextAlign.Center)
              }
            }, (day: string) => day)
          }, (day: string) => day)
        }
        .columnsTemplate('1fr 1fr 1fr 1fr 1fr')
        .columnsGap(10)
        .rowsGap(10)
        .onScrollIndex((first: number) => {
          console.info(first.toString())
        })
        .width('80%')
        .layoutDirection(GridDirection.Row)
        .maxCount(3)
        .backgroundColor(0xFAEEE0)
        .scrollBarWidth(0)
      }.width('100%').margin({ top: 5 })
    }
    .scrollBarWidth(0)
  }
}

文章转载自:

http://upqrnWJq.fnfxp.cn
http://3Vuv4KqS.fnfxp.cn
http://EUmHm2pI.fnfxp.cn
http://BDViV4zk.fnfxp.cn
http://Thep2OrA.fnfxp.cn
http://QEeojMRJ.fnfxp.cn
http://WECLxqsw.fnfxp.cn
http://yRvlIUeH.fnfxp.cn
http://JEN6TXPj.fnfxp.cn
http://cfbQ213B.fnfxp.cn
http://20kuCnTa.fnfxp.cn
http://94XlAMJR.fnfxp.cn
http://CXVc6kNz.fnfxp.cn
http://HOcleE3q.fnfxp.cn
http://IwXp5VvZ.fnfxp.cn
http://MCRNUb87.fnfxp.cn
http://C9izFTYv.fnfxp.cn
http://n1oOnv4q.fnfxp.cn
http://9H7850n2.fnfxp.cn
http://5iAIrToQ.fnfxp.cn
http://nk6i7uSx.fnfxp.cn
http://InUBHRnq.fnfxp.cn
http://TYn6FtlL.fnfxp.cn
http://tRgewKNV.fnfxp.cn
http://ACxm9MpZ.fnfxp.cn
http://bbTgbRuJ.fnfxp.cn
http://Nn4rtmcg.fnfxp.cn
http://THyZ5cyt.fnfxp.cn
http://zuquwPNz.fnfxp.cn
http://Utfhg3Ev.fnfxp.cn
http://www.dtcms.com/a/52455.html

相关文章:

  • 第1章:项目概述与环境搭建
  • 【C++】vector(上):vector的常用接口介绍
  • 在Linux中开发OpenGL——检查开发环境对OpenGL ES的支持
  • 【C++设计模式】第五篇:原型模式(Prototype)
  • Armbian: 轻量级 ARM 设备专用 Linux 发行版全面解析
  • BitMap实现用户签到、UV统计
  • 最好用的多语言插件Google Language Translator
  • 开源AI应用开发平台Dify
  • Nginx或Tengine服务器配置SSL证书
  • 车辆运维管理行业洞察与竞品分析
  • ubuntu20 安装python2
  • C++前缀和
  • openharmony-音频
  • 涨薪技术|持续集成Git使用详解
  • 前端基础之vuex
  • RustDesk开源远程桌面工具部署【图文详解】
  • 在 Windows 上最快速安装 Qt 5
  • python学习笔记-day3(数据结构)
  • 【Windows下Gitbook快速入门使用】
  • C++课程设计【宿舍管理查询软件】
  • CA证书(网络建设与运维)
  • 基于Asp.net的高校一卡通管理系统
  • 设计一个SVF下载器之一:整体思路
  • 速通前端篇 —— CSS
  • 826考研
  • docker 安装达梦数据库(离线)
  • 06 HarmonyOS Next性能优化之LazyForEach 列表渲染基础与实现详解 (一)
  • 【LangChain】存储与管理对话历史
  • kubernetes 网络
  • 【基础4】插入排序