未验证 提交 4e5c2395 编写于 作者: O openharmony_ci 提交者: Gitee

!13390 翻译完成 13198

Merge pull request !13390 from ester.zhou/TR-13198
...@@ -60,26 +60,15 @@ struct ComponentA { ...@@ -60,26 +60,15 @@ struct ComponentA {
this.label = (this.languageCode === 'en') ? 'Number' : 'Count' this.label = (this.languageCode === 'en') ? 'Number' : 'Count'
}) })
} }
.margin({ bottom: 50 }) .margin({ top: 50, bottom: 50 })
Row() { Row() {
Button (`Change @StorageLink decorated variable: ${this.varA}`).height(40).fontSize(14) Button (`Change @StorageLink decorated variable: ${this.varA}`).height(40).fontSize(14)
.onClick(() => { .onClick(() => {
this.varA++ this.varA++
}) })
}.margin({ bottom: 50 })
Row() {
Button (`Change @StorageProp decorated variable: ${this.languageCode}`).height(40).fontSize(14)
.onClick(() => {
if (this.languageCode === 'zh') {
this.languageCode = 'en'
} else {
this.languageCode = 'zh'
}
})
} }
} }.width('100%')
} }
} }
``` ```
...@@ -110,27 +99,26 @@ One-way data binding can be established between a component and the **LocalStora ...@@ -110,27 +99,26 @@ One-way data binding can be established between a component and the **LocalStora
> **NOTE** > **NOTE**
> >
> If a **LocalStorage** instance has initial values assigned when being created, these values will be used for the **@LocalStorageLink** and **@LocalStorageProp** decorated state variables in the component. Otherwise, the initial values assigned for **@LocalStorageLink** and **@LocalStorageProp** will be used instead. > If a **LocalStorage** instance does not have an initial value assigned when being created, it can use the initial value defined by **@LocalStorageLink** or **@LocalStorageProp** in the component.
### Example 1: Creating a LocalStorage Instance in an Ability ### Example 1: Creating a LocalStorage Instance in an Ability
The **LocalStorage** is loaded through the **loadContent** API. For details, see [loadContent](../reference/apis/js-apis-window.md#loadcontent9-1). The **LocalStorage** is loaded through the **loadContent** API. For details, see [loadContent](../reference/apis/js-apis-window.md#loadcontent9-1).
```ts ```ts
// MainAbility.ts import UIAbility from '@ohos.app.ability.UIAbility';
import Ability from '@ohos.application.Ability'
export default class MainAbility extends Ability { export default class EntryAbility extends UIAbility {
storage: LocalStorage storage: LocalStorage
onCreate() { onCreate() {
this.storage = new LocalStorage() this.storage = new LocalStorage()
this.storage.setOrCreate('storageSimpleProp', 121) this.storage.setOrCreate('storageSimpleProp', 121)
console.info('[Demo MainAbility onCreate]') console.info('[Demo EntryAbility onCreate]')
} }
onDestroy() { onDestroy() {
console.info('[Demo MainAbility onDestroy]') console.info('[Demo EntryAbility onDestroy]')
} }
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
...@@ -139,15 +127,15 @@ export default class MainAbility extends Ability { ...@@ -139,15 +127,15 @@ export default class MainAbility extends Ability {
} }
onWindowStageDestroy() { onWindowStageDestroy() {
console.info('[Demo] MainAbility onWindowStageDestroy') console.info('[Demo] EntryAbility onWindowStageDestroy')
} }
onForeground() { onForeground() {
console.info('[Demo] MainAbility onForeground') console.info('[Demo] EntryAbility onForeground')
} }
onBackground() { onBackground() {
console.info('[Demo] MainAbility onBackground') console.info('[Demo] EntryAbility onBackground')
} }
} }
``` ```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册