欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 游戏 > hongmeng开发

hongmeng开发

2025/5/1 17:55:03 来源:https://blog.csdn.net/qq_46025779/article/details/140979825  浏览:    关键词:hongmeng开发

726520eeb30fa0df22b90693972667e

89238b5287c7651d8ea2cf3b8ab528c

639b42b30990e0fc3dba3a68364d3d7

2bc0a582576a64fc2eada9b983e1d49

4b35b27c828e34e13332173aac48e98

c7524e5a36d6ed39dc02b2ed3f7b5d2

0dd45376bd9cf52d570d0416e5b96b9

Image图片组件

25d44fe048362c6e85749191dcfd0a0

5f44fcb3b161592e3f7e760cd4adb78

2d60c13d6b69497bcca344072e95c9c

Text组件

image-20240805163118044

如在两个限定目录里面定义完后,也要在 base牡蛎下去定义一下,不然会报错

TextInput

image-20240805163620797

Button

image-20240805164834562

Slider

image-20240805165709309

案例
@State imageWidth:number=30//构建 → 界面build() {Column(){Image($r('app.media.startIcon')).width(this.imageWidth)TextInput({placeholder:this.imageWidth.toFixed(0)}).width(240).height(40).onChange(value=>{this.imageWidth=parseInt(value)})Row(){Button('增加').onClick(()=>{this.imageWidth+=10})Button('缩小').onClick(()=>{this.imageWidth-=10})}Slider({min:0,max:100,step:10,value:this.imageWidth,style:SliderStyle.InSet,//在内还是在外direction:Axis.Horizontal,//进度条水平还是 垂直reverse:false//是否反向滑动}).showTips(true)//是否显示百分比.onChange(value=>{this.imageWidth=value})}.width('100%').height('100%').padding(20).backgroundColor(Color.Pink).padding(20)

Column和Row

image-20240805171608871

justifyContent

image-20240805171722299

image-20240805171829495

Divider分割线

image-20240805172129084

渲染控制

image-20240805173441673

案例
class Item{name:stringimage:ResourceStrprice:numberconstructor(name:string,image:ResourceStr,price:number) {this.name=namethis.image=imagethis.price=price}}@Entry
@Component
struct demo {@State message:number=1;@State color:string='#CCCC'@State count:number=8888@State imageWidth:number=30private items: Array<Item>=[new Item('华为60',$r('app.media.app_icon'),6999),new Item('华为60',$r('app.media.app_icon'),6999),new Item('华为60',$r('app.media.app_icon'),6999),new Item('华为60',$r('app.media.app_icon'),6999),new Item('华为60',$r('app.media.app_icon'),6999)]//构建 → 界面build() {Column(){Text('商品列表').fontSize(24).fontWeight(FontWeight.Bold).width('100%')ForEach(this.items,(item:Item)=>{Row(){Image(item.image).width(60)Column(){Text(item.name).fontSize(16)Text(item.price.toFixed(0)).fontColor(Color.Red).fontSize(13)}.alignItems(HorizontalAlign.Start)}.width('100%').height(80).justifyContent(FlexAlign.SpaceBetween).padding({left:15,right:15}).margin({top:30}).backgroundColor(Color.White).borderRadius(10)})}.width('100%').height('100%').padding(20).backgroundColor(Color.Pink).padding(20)}
}

image-20240805180538050

list组件

image-20240805180905343

案例
class Item{name:stringimage:ResourceStrprice:numberconstructor(name:string,image:ResourceStr,price:number) {this.name=namethis.image=imagethis.price=price}}@Entry
@Component
struct demo {@State message:number=1;@State color:string='#CCCC'@State count:number=8888@State imageWidth:number=30private items: Array<Item>=[new Item('华为60',$r('app.media.app_icon'),6999),new Item('华为60',$r('app.media.app_icon'),6999),new Item('华为60',$r('app.media.app_icon'),6999),new Item('华为60',$r('app.media.app_icon'),6999),new Item('华为60',$r('app.media.app_icon'),6999),new Item('华为60',$r('app.media.app_icon'),6999),new Item('华为60',$r('app.media.app_icon'),6999),new Item('华为60',$r('app.media.app_icon'),6999)]//构建 → 界面build() {Column(){Text('商品列表').fontSize(24).fontWeight(FontWeight.Bold).width('100%').margin({bottom:30})List({space:20}){ForEach(this.items,(item:Item)=>{ListItem(){Row(){Image(item.image).width(60)Column(){Text(item.name).fontSize(16)Text(item.price.toFixed(0)).fontColor(Color.Red).fontSize(13)}.alignItems(HorizontalAlign.Start)}.width('100%').height(100).justifyContent(FlexAlign.SpaceBetween).padding({left:15,right:15}).backgroundColor(Color.White).borderRadius(10)}})}.layoutWeight(1)}.width('100%').height('100%').padding(20).backgroundColor(Color.Pink).padding(20)}
}

自定义组件

image-20240805182406350

//全局自定义构建函数
@Builder function ItemCard(item:Item){Row(){Image(item.image).width(60)Column(){Text(item.name).fontSize(16)Text(item.price.toFixed(0)).fontColor(Color.Red).fontSize(13)}.alignItems(HorizontalAlign.Start)}.width('100%').height(100).justifyContent(FlexAlign.SpaceBetween).padding({left:15,right:15}).backgroundColor(Color.White).borderRadius(10)
}

使用:

image-20240805184915610

//全局公共样式函数
@Styles function StylesQuan(){.width('100%').height('100%').padding(20).backgroundColor(Color.Pink).padding(20)
}

使用:

image-20240805184956602

注意:只能抽取公共的,例如text,image这种有特有属性的组件就用不了

需要**@Extend()**继承该组件才可以(继承模式只能写在全局里)

image-20240805185337027

image-20240805185529403

image-20240805185619356

状态管理

@state

image-20240805210707410

@prop和Link

image-20240805215259682

@Provide和@Consume

@objectLink和@Observed

嵌套对象

image-20240806161558147

数组元素

image-20240806161709128

页面路由

image-20240806162947708

image-20240806163125689

image-20240806163502852

image-20240806163533441

页面动画 有点薄弱

image-20240806170104129

image-20240806171659736

Stage模型

image-20240806174426788

配置文件

UIAbitity生命周期

image-20240806194730531

image-20240806194947197

组件的生命周期

image-20240806201616296

其中builder函数创建后的是和销毁前的是组件生命周期,可以在任意组件中使用,而页面的生命周期只能在@entry中使用

UIAlility启动模式

image-20240806203537132

image-20240806203611801

image-20240806203839588

网络连接

http数据请求

image-20240806210331455

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词