

本案例主要运用了交互点击事件和基础的算术运算符的应用,难度并不大,卡片的制作相对来说并不是太难,简单的整体到局部。
在鸿蒙开发中,交互点击事件是构建用户界面交互性的重要组成部分。这些事件允许应用对用户的输入做出响应,比如点击、长按或拖动手势等。


@Entry
@Component
struct Index {
// 声明状态
@State color:string='#fff'
@State count:number=2998
build() {
Column() {
Column(){
Image($r('app.media.xhs_img_03'))
.width(200)
.borderRadius(10)
Text('反emo文学,太搞笑了')
.fontSize(13)
.fontColor(Color.White)
.width('100%')
.fontWeight(500)
.margin({left:20,top:10,bottom:10})
}
Row() {
Row() {
Image($r('app.media.tx_01'))
.width(20)
.borderRadius(10)
.margin({right:5})
Text('金金妈妈')
.fontColor(Color.White)
.fontSize(12)
}
Row() {
Image($r('app.media.ic_love'))
.width(14)
.margin({right:2})
.fillColor(this.color)
Text(this.count.toString())
.fontSize(12)
.fontColor(this.color)
}
.onClick(()=>{
// 修改数字
this.count+=1
// 修改颜色
this.color='#ff0000'
})
}
.width('100%')
.padding({left:10,right:10})
.justifyContent(FlexAlign.SpaceBetween)
}
.width(220)
.height(500)
.margin(20)
.padding(10)
.backgroundColor(Color.Black)
}
}