• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import { Entry, Text, TextAttribute, Column, Component, Button, ButtonAttribute, ClickEvent } from '@ohos.arkui.component'  // TextAttribute should be insert by ui-plugins
2import { State } from '@ohos.arkui.stateManagement' // should be insert by ui-plugins
3import hilog from '@ohos.hilog'
4
5@Entry
6@Component
7struct MyStateSample {
8  @State stateVar: string = 'state var';
9  message: string = 'var';
10  changeValue() {
11    this.stateVar+='~'
12  }
13  build() {
14    Column(undefined) {
15      Text('Hello World').fontSize(20)
16      Button(this.message).backgroundColor('#FFFF00FF')
17        .onClick((e: ClickEvent) => {
18          hilog.info(0x0000, 'testTag', 'On Click');
19          this.changeValue();
20        })
21      Text(this.stateVar).fontSize(20)
22      Child({stateVar: this.stateVar} as __Options_Child)
23    }
24  }
25}
26
27@Component
28struct Child {
29  @State stateVar: string = 'Child';
30  build() {
31    Text(this.stateVar).fontSize(50)
32  }
33}