
ArkTS 语言
- ArkTS 是华为自研的开发语言。
- 它在TypeScript(简称TS)的基础上,匹配ArkUI框架,扩展了声明式UI、状态管理等相应的能力,让开发者以更简洁、更自然的方式开发跨端应用。
学习ArkTs
- 数据类型参见TypeScript
- 编写模式参考JavaScript
- 真好(huawei shi dong yingxiao de)
ArkTs 代码
@Entry
@Component
struct Index {
@State message: string = 'Hello World'
private a:string = 'fuck frontend'
@State aValue:string = '1'
@State bValue:string = '23'
@State objValue:ObjectLinkDemoClass = {num:1,txt:'ObjectLinkDemoClass'}
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
Text(this.aValue).fontColor('#0099ff');
SomeCom({ propsLinksValue: $aValue, propsPropValue: this.bValue, propsObjectLinkValue: this.objValue})
}
.width('100%')
}
.height('100%')
}
}
@Observed
class ObjectLinkDemoClass {
public num:number;
public txt:string;
}
@Component
struct SomeCom {
@State value:string = 'SomeComStates'
@Link propsLinksValue:string;
@Prop propsPropValue: string;
@ObjectLink propsObjectLinkValue:ObjectLinkDemoClass;
build() {
Column(){
Text(this.value);
Text(this.propsLinksValue);
Text(this.propsPropValue);
Text(this.propsObjectLinkValue.txt);
Button({type:ButtonType.Capsule}){
Text('子组件修改@Link传参').fontColor('#ffffff')
}.onClick(() => {
this.propsLinksValue = 'fuck'
}).padding(10).margin(10)
}
}
}