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

HarmonyOS ArkTS 中DatePicker先择时间 路由跳转并传值到其它页

效果

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

代码

代码里有TextTimerController 这一种例用方法较怪,Text ,Button Datepicker 的使用。
import router from '@ohos.router’则是引入路由模块。


import router from '@ohos.router'
@Entry
@Component
struct TextnewClock {textTimerController: TextTimerController = new TextTimerController()@State format: string = 'mm:ss.SS'@State value: string =''@State isLunar: boolean = falseprivate selectedDate: Date = new Date('2021-08-08')@State getDate:string=""build() {Column() {TextTimer({ isCountDown: true, count: 30000, controller: this.textTimerController }).format(this.format).fontColor(Color.Black).fontSize(50).onTimer((utc: number, elapsedTime: number) => {this.value=elapsedTime.toString()console.info('textTimer notCountDown utc is:' + utc + ', elapsedTime: ' + elapsedTime)})Row() {Button("开始").onClick(() => {this.textTimerController.start()})Button("停止").onClick(() => {this.textTimerController.pause()})Button("重置").onClick(() => {this.textTimerController.reset()})}TextInput({text: this.value,placeholder:'时间'}).backgroundColor('#fff').type(InputType.Normal).onChange(value=>{})Button('跳转'+ this.value, { type: ButtonType.Capsule, stateEffect: true }).backgroundColor(0x317aff).width(200).onClick(()=>{router.pushUrl({url:"pages/TimePage",params:{params: this.value}})})TextInput({text:  this.getDate,placeholder:'时间'}).backgroundColor('#fff').type(InputType.Normal).onChange(value=>{})Button('跳转'+  this.getDate, { type: ButtonType.Capsule, stateEffect: true }).backgroundColor(0x317aff).width(200).onClick(()=>{router.pushUrl({url:"pages/TimePage",params:{params: this.getDate}})})DatePicker({start: new Date('1970-1-1'),end: new Date('2100-1-1'),selected: this.selectedDate}).lunar(this.isLunar).onChange((value: DatePickerResult) => {this.selectedDate.setFullYear(value.year, value.month, value.day)console.info('select current date is: ' + JSON.stringify(value))this.getDate= value.year.toString()+"-"+ value.month.toString()+"-"+value.day.toString()})}.justifyContent(FlexAlign.Center).width('100%').height('100%')}
}

跳转的页TimePage, private content:string =router.getParams()?.[“params”]这一段是获取传过来的参数。

import router from '@ohos.router'
@Entry
@Component
struct TimePage {private  content:string =router.getParams()?.["params"]build() {Row() {Column() {Text(this.content).fontSize(50).fontWeight(FontWeight.Bold)}.width('100%')}.height('100%')}
}
http://www.lryc.cn/news/264045.html

相关文章:

  • Axure RP 8 for Mac/win中文版:打造完美交互式原型设计体验
  • 迪文屏开发保姆级教程——页面键盘
  • Unity的UI界面——Text/Image
  • sklearn和tensorflow的理解
  • css中BFC
  • 华为OD机试 - 小朋友来自多少小区(Java JS Python C)
  • 前端:NPM的介绍和使用
  • 力扣57. 插入区间
  • Linux c++开发-11-Socket TCP编程简单案例
  • ros2机器人常规控制流程
  • 分布式全局ID之雪花算法
  • 拿到服务器该做的事和升级docker engine
  • 【VScode和Leecode的爱恨情仇】command ‘leetcode.signin‘ not found
  • mangokit:golang web项目管理工具,使用proto定义http路由和错误
  • 微信小程序实现一个简单的登录功能
  • whisper深入-语者分离
  • LuaJava操作Java的方法
  • oracle怎样才算开启了内存大页?
  • 【halcon深度学习之那些封装好的库函数】determine_dl_model_detection_param
  • 跟着我学Python进阶篇:01.试用Python完成一些简单问题
  • neo4j-Py2neo使用
  • uint29传输格式
  • Linux:终端定时自动注销
  • STM32F103RCT6开发板M3单片机教程06--定时器中断
  • 数据库故障Waiting for table metadata lock
  • Springboot数据校验与异常篇
  • 第三十六章 XML 模式的高级选项 - 创建子类型的替换组
  • 堆与二叉树(上)
  • HBase查询的一些限制与解决方案
  • 软件开发 VS Web开发