ARTICLE DETAIL

资讯详情

深耕网站建设、视觉设计与SEO优化的一线实战洞察。

【ArkTS-模式-动画-路由】

【ArkTS-模式-动画-路由】

ArkTS-模式-动画-路由

  • ■ MVVM模式
    • ■ 1. View
    • ■ 2. Model
    • ■ 3. ViewModel
  • ■ router 路由
  • ■ animation

■ MVVM模式

■ 1. View

■ 2. Model

Model层是应用的原始数据提供者,代表应用的核心业务逻辑和数据。

■ 3. ViewModel


■ router 路由

1.importrouterimportrouterfrom'@ohos.router'2.添加跳转Button(){Text(`${this.ResetBluetooth}`)// .width('20%')}.width('40%').height(50).onClick(()=>{// 跳转到设置页面(页面路径需在main_pages.json中配置)router.pushUrl({url:'pages/RemoteControl'// 目标页面的路径})})3.路由配置文件(main_pages.json) 在 moudule.json5中的"pages":"$profile:main_pages",点击跳到main_pages.json 添加页面信息。{"src":["pages/Index","pages/RemoteControl"]}

■ animation

@Entry @ComponentstructPressScaleImage{@State scaleValue:number=1build(){Column(){Text('点击缩放效果').fontSize(18).margin(20)Image($r('app.media.stop_open')).width(80).height(80).scale({x:this.scaleValue,y:this.scaleValue}).animation({// 全局动画配置duration:100,curve:Curve.EaseOut}).onTouch((event:TouchEvent)=>{if(event.type===TouchType.Down){this.scaleValue=0.95// 按下缩小}elseif(event.type===TouchType.Up){this.scaleValue=1// 抬起恢复}})}.width('100%').height('100%').justifyContent(FlexAlign.Center).alignItems(HorizontalAlign.Center)}}

点击有缩放效果

返回列表