第一个eTS HarmonyOS项目
使用eTS开发HarmonyOS应用
eTS是一种脚本语言,与TypeScript和JavaScript使用语法相近,会让我们在使用上比较接近web开发,适合我们快速上手与学习。
基本效果
组件使用
本处共使用两个组件,Text与Button,组件功能如下:
Text组件:
参数名 | 参数类型 | 必填 | 参数描述 |
---|---|---|---|
content | string Resource | 否 | 文本内容。包含子组件Span时不生效,显示Span内容,并且此时text组件的样式不生效。默认值:’ ’ |
Button组件:
参数名 | 参数类型 | 必填 | 参数描述 |
---|---|---|---|
type | ButtonType | 否 | 描述按钮显示样式。默认值:ButtonType.Capsule |
stateEffect | boolean | 否 | 按钮按下时是否开启按压态显示效果,当设置为false时,按压效果关闭。 默认值:true |
代码实现
Index.ets:
@Entry
@Component
struct Index {
@State message: string = 'Hello World'
@State count: number = 0 //实现变换
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button(){
Text("Clink me")
.fontSize(30)
.fontWeight(FontWeight.Bold)
}.onClick(()=>
{
if(this.count == 0){
this.message = "Hello HarmonyOS"
this.count = 1
}else{
this.message = "Hello World"
this.count = 0
}
})
.size({width:300,height:100})
.padding(20)
}
.width('100%')
}
.height('100%')
}
}
更多技术问题请关注博主,(公众浩:程序员阿诺斯)