1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| import ohos.base.* import ohos.component.* import ohos.state_manage.* import ohos.state_macro_manage.*
@Entry @Component class MyView { let p0 = PersistentStorage.persistProp("Name", "Adonis") let p1 = PersistentStorage.persistProp("Age", 24) let p2 = PersistentStorage.persistProp("Height", 180.0) let p3 = PersistentStorage.persistProp("Male", true) let p4 = PersistentStorage.persistProps([("Name1", "Alex"), ("Name2", "Aphrodite")])
@StorageLink["Name"] var name: String = "" @StorageLink["Age"] var age: Int64 = 0 @StorageLink["Height"] var height: Float64 = 0.0 @StorageLink["Male"] var male: Bool = true @StorageLink["Name1"] var name1: String = "" @StorageLink["Name2"] var name2: String = ""
func build() { Column(10) { Text("Name ${name}") Text("Age ${age}") Text("Heght ${height}") Text("Male ${male}") Text("Name1 ${name1} Name2 ${name2}")
Button("change age").onClick { e => age += 1 }
Button("clear age").onClick { e => PersistentStorage.deleteProp("Age") } } } }
|