source stringlengths 14 113 | code stringlengths 10 21.3k |
|---|---|
application-dev\ui\state-management\arkts-custom-components-access-restrictions.md | @Entry
@Component
struct AccessRestrictions {
build() {
Column() {
ComponentChild({prop_value: "Hello"})
}
.width('100%')
}
}
@Component
struct ComponentChild {
// The private access is not allowed and an alarm is reported.
@Require @Prop private prop_value: string = "Hello";
build() {
C... |
application-dev\ui\state-management\arkts-custom-components-access-restrictions.md | Property 'prop_value' can not be decorated with both @Require and private.
Property 'prop_value' is private and can not be initialized through the component constructor. |
application-dev\ui\state-management\arkts-custom-components-access-restrictions.md | @Entry
@Component
struct AccessRestrictions {
build() {
Column() {
ComponentChild({prop_value: "Hello"})
}
.width('100%')
}
}
@Component
struct ComponentChild {
@Require @Prop prop_value: string = "Hello";
build() {
Column() {
Text("Hello")
.fontSize(50)
.fontWeight(F... |
application-dev\ui\state-management\arkts-custom-components-freeze.md | import { router } from '@kit.ArkUI';
@Entry
@Component({ freezeWhenInactive: true })
struct Page1 {
@StorageLink('PropA') @Watch("first") storageLink: number = 47;
first() {
console.info("first page " + `${this.storageLink}`)
}
build() {
Column() {
Text(`From first Page ${this.storageLink}`).fo... |
application-dev\ui\state-management\arkts-custom-components-freeze.md | import { router } from '@kit.ArkUI';
@Entry
@Component({ freezeWhenInactive: true })
struct Page2 {
@StorageLink('PropA') @Watch("second") storageLink2: number = 1;
second() {
console.info("second page: " + `${this.storageLink2}`)
}
build() {
Column() {
Text(`second Page ${this.storageLink2}`)... |
application-dev\ui\state-management\arkts-custom-components-freeze.md | @Entry
@Component
struct TabContentTest {
@State @Watch("onMessageUpdated") message: number = 0;
private data: number[] = [0, 1]
onMessageUpdated() {
console.info(`TabContent message callback func ${this.message}`)
}
build() {
Row() {
Column() {
Button('change message').onClick(() => {... |
application-dev\ui\state-management\arkts-custom-components-freeze.md | // Basic implementation of IDataSource used to listening for data.
class BasicDataSource implements IDataSource {
private listeners: DataChangeListener[] = [];
private originDataArray: string[] = [];
public totalCount(): number {
return 0;
}
public getData(index: number): string {
return this.origin... |
application-dev\ui\state-management\arkts-custom-components-freeze.md | @Entry
@Component
struct MyNavigationTestStack {
@Provide('pageInfo') pageInfo: NavPathStack = new NavPathStack();
@State @Watch("info") message: number = 0;
@State logNumber: number = 0;
info() {
console.info(`freeze-test MyNavigation message callback ${this.message}`);
}
@Builder
PageMap(name: str... |
application-dev\ui\state-management\arkts-custom-components-freeze.md | @Reusable
@Component({freezeWhenInactive: true})
struct ChildComponent {
@Link @Watch('descChange') desc: string;
@State count: number = 0;
descChange() {
console.info(`ChildComponent messageChange ${this.desc}`);
}
aboutToReuse(params: Record<string, ESObject>): void {
this.count = params.count as n... |
application-dev\ui\state-management\arkts-custom-components-freeze.md | import { hiTraceMeter } from '@kit.PerformanceAnalysisKit';
// Basic implementation of IDataSource used to listening for data.
class BasicDataSource implements IDataSource {
private listeners: DataChangeListener[] = [];
private originDataArray: string[] = [];
public totalCount(): number {
return 0;
}
pu... |
application-dev\ui\state-management\arkts-custom-components-freeze.md | // index.ets
@Component
struct ChildOfParamComponent {
@Prop @Watch('onChange') child_val: number;
onChange() {
console.log(`Appmonitor ChildOfParamComponent: child_val changed:${this.child_val}`);
}
build() {
Column() {
Text(`Child Param: ${this.child_val}`);
}
}
}
@Component
struct Para... |
application-dev\ui\state-management\arkts-custom-components-freeze.md | import { hiTraceMeter } from '@kit.PerformanceAnalysisKit';
// Basic implementation of IDataSource used to listening for data.
class BasicDataSource implements IDataSource {
private listeners: DataChangeListener[] = [];
private originDataArray: string[] = [];
public totalCount(): number {
return 0;
}
pu... |
application-dev\ui\state-management\arkts-custom-components-freezeV2.md | import { router } from '@kit.ArkUI';
@ObservedV2
export class Book {
@Trace name: string = "100";
constructor(page: string) {
this.name = page;
}
}
@Entry
@ComponentV2({ freezeWhenInactive: true })
export struct Page1 {
@Local bookTest: Book = new Book("A Midsummer Night's Dream");
@Monitor("bookTest.... |
application-dev\ui\state-management\arkts-custom-components-freezeV2.md | import { router } from '@kit.ArkUI';
@Entry
@ComponentV2
struct Page2 {
build() {
Column() {
Text(`This is the page2`).fontSize(25)
Button('Back')
.onClick(() => {
router.back();
})
}
}
} |
application-dev\ui\state-management\arkts-custom-components-freezeV2.md | @Entry
@ComponentV2
struct TabContentTest {
@Local message: number = 0;
@Local data: number[] = [0, 1];
build() {
Row() {
Column() {
Button('change message').onClick(() => {
this.message++;
})
Tabs() {
ForEach(this.data, (item: number) => {
TabCo... |
application-dev\ui\state-management\arkts-custom-components-freezeV2.md | @Entry
@ComponentV2
struct MyNavigationTestStack {
@Provider('pageInfo') pageInfo: NavPathStack = new NavPathStack();
@Local message: number = 0;
@Monitor('message') info() {
console.info(`freeze-test MyNavigation message callback ${this.message}`);
}
@Builder
PageMap(name: string) {
if (name === ... |
application-dev\ui\state-management\arkts-custom-components-freezeV2.md | @Entry
@ComponentV2
struct RepeatVirtualScrollFreeze {
@Local simpleList: Array<string> = [];
@Local bgColor: Color = Color.Pink;
aboutToAppear(): void {
for (let i = 0; i < 7; i++) {
this.simpleList.push(`item${i}`);
}
}
build() {
Column() {
Row() {
Button(`Reduce length to ... |
application-dev\ui\state-management\arkts-custom-components-freezeV2.md | // Disable component freezing.
@ComponentV2({ freezeWhenInactive: false })
struct ChildComponent {
@Param @Require message: string = ``;
@Param @Require bgColor: Color = Color.Pink;
@Monitor(`bgColor`)
onBgColorChange(monitor: IMonitor) {
// When the bgColor changes, components in the cache pool are re-rend... |
application-dev\ui\state-management\arkts-custom-components-freezeV2.md | @ComponentV2
struct ChildOfParamComponent {
@Require @Param child_val: number;
@Monitor('child_val') onChange(m: IMonitor) {
console.log(`Appmonitor ChildOfParamComponent: changed ${m.dirty[0]}: ${m.value()?.before} -> ${m.value()?.now}`);
}
build() {
Column() {
Text(`Child Param: ${this.child_v... |
application-dev\ui\state-management\arkts-declarative-ui-description.md | Column() {
Text('item 1')
Divider()
Text('item 2')
} |
application-dev\ui\state-management\arkts-declarative-ui-description.md | Image('https://xyz/test.jpg') |
application-dev\ui\state-management\arkts-declarative-ui-description.md | // Parameter of the string type
Text('test')
// Add application resources in $r format, which can be used in multi-language scenarios.
Text($r('app.string.title_value'))
// No mandatory parameters
Text() |
application-dev\ui\state-management\arkts-declarative-ui-description.md | Image(this.imagePath)
Image('https://' + this.imageUrl)
Text(`count: ${this.count}`) |
application-dev\ui\state-management\arkts-declarative-ui-description.md | Text('test')
.fontSize(12) |
application-dev\ui\state-management\arkts-declarative-ui-description.md | Image('test.jpg')
.alt('error.jpg')
.width(100)
.height(100) |
application-dev\ui\state-management\arkts-declarative-ui-description.md | Text('hello')
.fontSize(this.size)
Image('test.jpg')
.width(this.count % 2 === 0 ? 100 : 200)
.height(this.offset + 100) |
application-dev\ui\state-management\arkts-declarative-ui-description.md | Text('hello')
.fontSize(20)
.fontColor(Color.Red)
.fontWeight(FontWeight.Bold) |
application-dev\ui\state-management\arkts-declarative-ui-description.md | Button('Click me')
.onClick(() => {
this.myText = 'ArkUI';
}) |
application-dev\ui\state-management\arkts-declarative-ui-description.md | Button('add counter')
.onClick(() => {
this.counter += 2;
}) |
application-dev\ui\state-management\arkts-declarative-ui-description.md | myClickHandler(): void {
this.counter += 2;
}
...
Button('add counter')
.onClick(this.myClickHandler.bind(this)) |
application-dev\ui\state-management\arkts-declarative-ui-description.md | fn = () => {
console.info(`counter: ${this.counter}`)
this.counter++
}
...
Button('add counter')
.onClick(this.fn) |
application-dev\ui\state-management\arkts-declarative-ui-description.md | Column() {
Text('Hello')
.fontSize(100)
Divider()
Text(this.myText)
.fontSize(100)
.fontColor(Color.Red)
} |
application-dev\ui\state-management\arkts-declarative-ui-description.md | Column() {
Row() {
Image('test1.jpg')
.width(100)
.height(100)
Button('click +1')
.onClick(() => {
console.info('+1 clicked!');
})
}
} |
application-dev\ui\state-management\arkts-environment.md | // Save languageCode to AppStorage. The default value is en.
Environment.envProp('languageCode', 'en'); |
application-dev\ui\state-management\arkts-environment.md | @StorageProp('languageCode') lang: string = 'en'; |
application-dev\ui\state-management\arkts-environment.md | // Save the device language code to AppStorage.
Environment.envProp('languageCode', 'en');
@Entry
@Component
struct Index {
@StorageProp('languageCode') languageCode: string = 'en';
build() {
Row() {
Column() {
// Output the current device language code.
Text(this.languageCode)
}
... |
application-dev\ui\state-management\arkts-environment.md | // Use Environment.envProp to save the device language code to AppStorage.
Environment.envProp('languageCode', 'en');
// Obtain the one-way bound languageCode variable from AppStorage.
const lang: SubscribedAbstractProperty<string> = AppStorage.prop('languageCode');
if (lang.get() === 'en') {
console.info('Hi');
} e... |
application-dev\ui\state-management\arkts-environment.md | // EntryAbility.ets
import { UIAbility } from '@kit.AbilityKit';
import { window } from '@kit.ArkUI';
export default class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage: window.WindowStage) {
windowStage.loadContent('pages/Index');
let window = windowStage.getMainWindow()
window.then(w... |
application-dev\ui\state-management\arkts-extend.md | @Extend(UIComponentName) function functionName { ... } |
application-dev\ui\state-management\arkts-extend.md | // @Extend(Text) supports the private attribute fontColor of the Text component.
@Extend(Text) function fancy () {
.fontColor(Color.Red)
}
// superFancyText can call the predefined method fancy.
@Extend(Text) function superFancyText(size:number) {
.fontSize(size)
.fancy()
} |
application-dev\ui\state-management\arkts-extend.md | // xxx.ets
@Extend(Text) function fancy (fontSize: number) {
.fontColor(Color.Red)
.fontSize(fontSize)
}
@Entry
@Component
struct FancyUse {
build() {
Row({ space: 10 }) {
Text('Fancy')
.fancy(16)
Text('Fancy')
.fancy(24)
}
}
} |
application-dev\ui\state-management\arkts-extend.md | @Extend(Text) function makeMeClick(onClick: () => void) {
.backgroundColor(Color.Blue)
.onClick(onClick)
}
@Entry
@Component
struct FancyUse {
@State label: string = 'Hello World';
onClickHandler() {
this.label = 'Hello ArkUI';
}
build() {
Row({ space: 10 }) {
Text... |
application-dev\ui\state-management\arkts-extend.md | @Extend(Text) function fancy (fontSize: number) {
.fontColor(Color.Red)
.fontSize(fontSize)
}
@Entry
@Component
struct FancyUse {
@State fontSizeValue: number = 20
build() {
Row({ space: 10 }) {
Text('Fancy')
.fancy(this.fontSizeValue)
.onClick(() => {
... |
application-dev\ui\state-management\arkts-extend.md | @Entry
@Component
struct FancyUse {
// Incorrect format. @Extend can be defined only globally, but not inside a component.
@Extend(Text) function fancy (fontSize: number) {
.fontSize(fontSize)
}
build() {
Row({ space: 10 }) {
Text('Fancy')
.fancy(16)
}
}
} |
application-dev\ui\state-management\arkts-extend.md | // Correct format.
@Extend(Text) function fancy (fontSize: number) {
.fontSize(fontSize)
}
@Entry
@Component
struct FancyUse {
build() {
Row({ space: 10 }) {
Text('Fancy')
.fancy(16)
}
}
} |
application-dev\ui\state-management\arkts-extend.md | @Entry
@Component
struct FancyUse {
@State label: string = 'Hello World'
build() {
Row({ space: 10 }) {
Text(`${this.label}`)
.fontStyle(FontStyle.Italic)
.fontWeight(100)
.backgroundColor(Color.Blue)
Text(`${this.label}`)
.fontStyle(FontStyle.Italic)
.fontWe... |
application-dev\ui\state-management\arkts-extend.md | @Extend(Text) function fancyText(weightValue: number, color: Color) {
.fontStyle(FontStyle.Italic)
.fontWeight(weightValue)
.backgroundColor(color)
} |
application-dev\ui\state-management\arkts-extend.md | @Entry
@Component
struct FancyUse {
@State label: string = 'Hello World'
build() {
Row({ space: 10 }) {
Text(`${this.label}`)
.fancyText(100, Color.Blue)
Text(`${this.label}`)
.fancyText(200, Color.Pink)
Text(`${this.label}`)
.fancyText(300, Color.Orange)
}.margin(... |
application-dev\ui\state-management\arkts-link.md | @Component
struct DateComponent {
@Link selectedDate: Date;
build() {
Column() {
Button(`child increase the year by 1`)
.onClick(() => {
this.selectedDate.setFullYear(this.selectedDate.getFullYear() + 1);
})
Button('child update the new date')
.margin(10)
.onClic... |
application-dev\ui\state-management\arkts-link.md | // Incorrect format. An error is reported during compilation.
@Link count: number = 10;
// Correct format.
@Link count: number; |
application-dev\ui\state-management\arkts-link.md | class Info {
info: string = 'Hello';
}
class Cousin {
name: string = 'Hello';
}
@Component
struct Child {
// Incorrect format. The data source types of @Link and @State are different.
@Link test: Cousin;
build() {
Text(this.test.name)
}
}
@Entry
@Component
struct Link... |
application-dev\ui\state-management\arkts-link.md | class Info {
info: string = 'Hello';
}
@Component
struct Child {
// Correct format.
@Link test: Info;
build() {
Text(this.test.info)
}
}
@Entry
@Component
struct LinkExample {
@State info: Info = new Info();
build() {
Column() {
// Correct format.
... |
application-dev\ui\state-management\arkts-link.md | class Info {
info: string = 'Hello';
}
@Component
struct Child {
@Link msg: string;
@Link info: string;
build() {
Text(this.msg + this.info)
}
}
@Entry
@Component
struct LinkExample {
@State message: string = 'Hello';
@State info: Info = new Info();
build() {
... |
application-dev\ui\state-management\arkts-link.md | class Info {
info: string = 'Hello';
}
@Component
struct Child {
@Link msg: string;
@Link info: Info;
build() {
Text(this.msg + this.info.info)
}
}
@Entry
@Component
struct LinkExample {
@State message: string = 'Hello';
@State info: Info = new Info();
build() {
... |
application-dev\ui\state-management\arkts-link.md | class GreenButtonState {
width: number = 0;
constructor(width: number) {
this.width = width;
}
}
@Component
struct GreenButton {
@Link greenButtonState: GreenButtonState;
build() {
Button('Green Button')
.width(this.greenButtonState.width)
.height(40)
.backgroundColor('#64bb5c')
... |
application-dev\ui\state-management\arkts-link.md | @Component
struct Child {
@Link items: number[];
build() {
Column() {
Button(`Button1: push`)
.margin(12)
.width(312)
.height(40)
.fontColor('#FFFFFF, 90%')
.onClick(() => {
this.items.push(this.items.length + 1);
})
Button(`Button2: replace... |
application-dev\ui\state-management\arkts-link.md | @Component
struct Child {
@Link value: Map<number, string>;
build() {
Column() {
ForEach(Array.from(this.value.entries()), (item: [number, string]) => {
Text(`${item[0]}`).fontSize(30)
Text(`${item[1]}`).fontSize(30)
Divider()
})
Button('child init map').onClick(() => ... |
application-dev\ui\state-management\arkts-link.md | @Component
struct Child {
@Link message: Set<number>;
build() {
Column() {
ForEach(Array.from(this.message.entries()), (item: [number, number]) => {
Text(`${item[0]}`).fontSize(30)
Divider()
})
Button('init set').onClick(() => {
this.message = new Set([0, 1, 2, 3, 4]);... |
application-dev\ui\state-management\arkts-link.md | @Entry
@Component
struct Parent {
@State sourceNumber: number = 0;
build() {
Column() {
Text(`sourceNumber of the parent component: ` + this.sourceNumber)
Child({ sourceNumber: this.sourceNumber })
Button('sourceNumber is changed in the parent component')
.onClick(() => {
th... |
application-dev\ui\state-management\arkts-link.md | @Component
struct Child {
@Link name: string | undefined;
build() {
Column() {
Button('Child change name to Bob')
.onClick(() => {
this.name = "Bob";
})
Button('Child change name to undefined')
.onClick(() => {
this.name = undefined;
})
}.w... |
application-dev\ui\state-management\arkts-link.md | @Observed
class Info {
public age: number = 0;
constructor(age: number) {
this.age = age;
}
}
@Component
struct LinkChild {
@Link testNum: number;
build() {
Text(`LinkChild testNum ${this.testNum}`)
}
}
@Entry
@Component
struct Parent {
@State info: Info = new Info(1);
build() {
Column(... |
application-dev\ui\state-management\arkts-link.md | @Observed
class Info {
public age: number = 0;
constructor(age: number) {
this.age = age;
}
}
@Component
struct LinkChild {
@Link testNum: Info;
build() {
Text(`LinkChild testNum ${this.testNum?.age}`)
.onClick(() => {
this.testNum.age += 1;
})
}
}
@Entry
@Component
struct Pa... |
application-dev\ui\state-management\arkts-link.md | class Score {
value: number;
constructor(value: number) {
this.value = value;
}
static changeScore1(score:Score) {
score.value += 1;
}
}
@Entry
@Component
struct Parent {
@State score: Score = new Score(1);
build() {
Column({space:8}) {
Text(`The value in Parent is ${this.score.value}... |
application-dev\ui\state-management\arkts-link.md | class Score {
value: number;
constructor(value: number) {
this.value = value;
}
static changeScore1(score:Score) {
score.value += 1;
}
}
@Entry
@Component
struct Parent {
@State score: Score = new Score(1);
build() {
Column({space:8}) {
Text(`The value in Parent is ${this.score.value}... |
application-dev\ui\state-management\arkts-localBuilder.md | @LocalBuilder MyBuilderFunction() { ... } |
application-dev\ui\state-management\arkts-localBuilder.md | this.MyBuilderFunction() |
application-dev\ui\state-management\arkts-localBuilder.md | class ReferenceType {
paramString: string = '';
}
@Entry
@Component
struct Parent {
@State variableValue: string = 'Hello World';
@LocalBuilder
citeLocalBuilder(params: ReferenceType) {
Row() {
Text(`UseStateVarByReference: ${params.paramString}`)
}
};
build() {
Column() {
this.ci... |
application-dev\ui\state-management\arkts-localBuilder.md | class ReferenceType {
paramString: string = '';
}
@Component
struct HelloComponent {
@Prop message: string;
build() {
Row() {
Text(`HelloComponent===${this.message}`)
}
}
}
@Entry
@Component
struct Parent {
@State variableValue: string = 'Hello World';
@LocalBuilder
citeLocalBuilder($$: ... |
application-dev\ui\state-management\arkts-localBuilder.md | class Data {
size: number = 0;
}
@Entry
@Component
struct Parent {
label: string = 'parent';
@State data: Data = new Data();
@Builder
componentBuilder($$: Data) {
Text(`builder + $$`)
Text(`${'this -> ' + this.label}`)
Text(`${'size : ' + $$.size}`)
Text(`------------------------`)
}
@L... |
application-dev\ui\state-management\arkts-localBuilder.md | @Entry
@Component
struct Parent {
@State label: string = 'Hello';
@LocalBuilder
citeLocalBuilder(paramA1: string) {
Row() {
Text(`UseStateVarByValue: ${paramA1}`)
}
}
build() {
Column() {
this.citeLocalBuilder(this.label)
}
}
} |
application-dev\ui\state-management\arkts-localBuilder.md | @Component
struct Child {
label: string = 'Child';
@BuilderParam customBuilderParam: () => void;
build() {
Column() {
this.customBuilderParam()
}
}
}
@Entry
@Component
struct Parent {
label: string = 'Parent';
@Builder componentBuilder() {
Text(`${this.label}`)
}
// @LocalBuilder c... |
application-dev\ui\state-management\arkts-localBuilder.md | @ObservedV2
class Info {
@Trace name: string = '';
@Trace age: number = 0;
}
@ComponentV2
struct ChildPage {
@Require @Param childInfo: Info;
build() {
Column() {
Text(`Custom component name :${this.childInfo.name}`)
.fontSize(20)
.fontWeight(FontWeight.Bold)
Text(`Custom compon... |
application-dev\ui\state-management\arkts-localstorage.md | let storage = new LocalStorage();
storage.setOrCreate('PropA', 48);
// Incorrect format. An error is reported during compilation.
@LocalStorageProp() localStorageProp: number = 1;
@LocalStorageLink() localStorageLink: number = 2;
// Correct format.
@LocalStorageProp('PropA') localStorageProp: ... |
application-dev\ui\state-management\arkts-localstorage.md | let para: Record<string,number> = { 'PropA': 47 };
let storage: LocalStorage = new LocalStorage(para); // Create an instance and initialize it with the given object.
let propA: number | undefined = storage.get('PropA'); // propA == 47
let link1: SubscribedAbstractProperty<number> = storage.link('PropA'); // link1.get()... |
application-dev\ui\state-management\arkts-localstorage.md | class Data {
code: number;
constructor(code: number) {
this.code = code;
}
}
// Create a new instance and initialize it with the given object.
let para: Record<string, number> = { 'PropA': 47 };
let storage: LocalStorage = new LocalStorage(para);
storage.setOrCreate('PropB', new Data(50));
@Component
struct... |
application-dev\ui\state-management\arkts-localstorage.md | // Create a new instance and initialize it with the given object.
let para: Record<string, number> = { 'PropA': 47 };
let storage: LocalStorage = new LocalStorage(para);
// Make LocalStorage accessible from the @Component decorated component.
@Entry(storage)
@Component
struct Parent {
// @LocalStorageProp creates a o... |
application-dev\ui\state-management\arkts-localstorage.md | // Create a LocalStorage instance.
let para: Record<string, number> = { 'PropA': 47 };
let storage: LocalStorage = new LocalStorage(para);
// Call the link API (available since API version 9) to create a two-way data synchronization with PropA. linkToPropA is a global variable.
let linkToPropA: SubscribedAbstractProper... |
application-dev\ui\state-management\arkts-localstorage.md | let count: Record<string, number> = { 'countStorage': 1 };
let storage: LocalStorage = new LocalStorage(count);
@Component
struct Child {
// Name the child component instance.
label: string = 'no name';
// Two-way synchronization with countStorage in LocalStorage.
@LocalStorageLink('countStorage') playCountLin... |
application-dev\ui\state-management\arkts-localstorage.md | // EntryAbility.ets
import { UIAbility } from '@kit.AbilityKit';
import { window } from '@kit.ArkUI';
export default class EntryAbility extends UIAbility {
para: Record<string, number> = {
'PropA': 47
};
storage: LocalStorage = new LocalStorage(this.para);
onWindowStageCreate(windowStage: window.WindowSta... |
application-dev\ui\state-management\arkts-localstorage.md | // index.ets
// Use the getShared API to obtain the LocalStorage instance shared by stage.
@Entry({ storage: LocalStorage.getShared() })
@Component
struct Index {
// You can use @LocalStorageLink/Prop to establish a relationship with the variables in the LocalStorage instance.
@LocalStorageLink('PropA') propA: num... |
application-dev\ui\state-management\arkts-localstorage.md | // Page.ets
@Builder
export function PageBuilder() {
Page()
}
// The Page component obtains the LocalStorage instance of the parent component Index.
@Component
struct Page {
@LocalStorageLink('PropA') propA: number = 2;
pathStack: NavPathStack = new NavPathStack();
build() {
NavDestination() {
Row(... |
application-dev\ui\state-management\arkts-localstorage.md | let localStorage1: LocalStorage = new LocalStorage();
localStorage1.setOrCreate('PropA', 'PropA');
let localStorage2: LocalStorage = new LocalStorage();
localStorage2.setOrCreate('PropB', 'PropB');
@Entry(localStorage1)
@Component
struct Index {
// PropA is in two-way synchronization with PropA in localStorage1.
... |
application-dev\ui\state-management\arkts-localstorage.md | let localStorage1: LocalStorage = new LocalStorage();
localStorage1.setOrCreate('PropA', 'PropA');
let localStorage2: LocalStorage = new LocalStorage();
localStorage2.setOrCreate('PropB', 'PropB');
@Entry(localStorage1)
@Component
struct Index {
// PropA is in two-way synchronization wit... |
application-dev\ui\state-management\arkts-localstorage.md | let localStorage1: LocalStorage = new LocalStorage();
localStorage1.setOrCreate('PropA', 'PropA');
let localStorage2: LocalStorage = new LocalStorage();
localStorage2.setOrCreate('PropB', 'PropB');
@Entry(localStorage1)
@Component
struct Index {
// PropA is in two-way synchronization wit... |
application-dev\ui\state-management\arkts-localstorage.md | let localStorageA: LocalStorage = new LocalStorage();
localStorageA.setOrCreate('PropA', 'PropA');
let localStorageB: LocalStorage = new LocalStorage();
localStorageB.setOrCreate('PropB', 'PropB');
let localStorageC: LocalStorage = new LocalStorage();
localStorageC.setOrCreate('PropC', 'PropC');
@Entry
@Component
st... |
application-dev\ui\state-management\arkts-localstorage.md | @Component
struct LocalStorLink {
@LocalStorageLink("LinkA") LinkA: number | null = null;
@LocalStorageLink("LinkB") LinkB: number | undefined = undefined;
build() {
Column() {
Text("@LocalStorageLink initialization, @LocalStorageLink value")
Text(this.LinkA + "").fontSize(20).onClick(() => {
... |
application-dev\ui\state-management\arkts-localstorage.md | @Entry
@Component
struct LocalDateSample {
@LocalStorageLink("date") selectedDate: Date = new Date('2021-08-08');
build() {
Column() {
Button('set selectedDate to 2023-07-08')
.margin(10)
.onClick(() => {
this.selectedDate = new Date('2023-07-08');
})
Button('incre... |
application-dev\ui\state-management\arkts-localstorage.md | @Entry
@Component
struct LocalMapSample {
@LocalStorageLink("map") message: Map<number, string> = new Map([[0, "a"], [1, "b"], [3, "c"]]);
build() {
Row() {
Column() {
ForEach(Array.from(this.message.entries()), (item: [number, string]) => {
Text(`${item[0]}`).fontSize(30)
Tex... |
application-dev\ui\state-management\arkts-localstorage.md | @Entry
@Component
struct LocalSetSample {
@LocalStorageLink("set") memberSet: Set<number> = new Set([0, 1, 2, 3, 4]);
build() {
Row() {
Column() {
ForEach(Array.from(this.memberSet.entries()), (item: [number, string]) => {
Text(`${item[0]}`)
.fontSize(30)
Divider()... |
application-dev\ui\state-management\arkts-localstorage.md | let storage = new LocalStorage();
storage.setOrCreate('count', 47);
class Model {
storage: LocalStorage = storage;
call(propName: string, value: number) {
this.storage.setOrCreate<number>(propName, value);
}
}
let model: Model = new Model();
@Entry({ storage: storage })
@Component
struct Test {
@LocalSt... |
application-dev\ui\state-management\arkts-mvvm-V2.md | // src/main/ets/pages/1-Basic.ets
@Entry
@ComponentV2
struct TodoList {
build() {
Column() {
Text('To-Dos')
.fontSize(40)
.margin({ bottom: 10 })
Text('Task1')
Text('Task2')
Text('Task3')
}
}
} |
application-dev\ui\state-management\arkts-mvvm-V2.md | // src/main/ets/pages/2-Local.ets
@Entry
@ComponentV2
struct TodoList {
@Local isFinish: boolean = false;
build() {
Column() {
Text('To-Dos')
.fontSize(40)
.margin({ bottom: 10 })
Row() {
// Add the finished.png and unfinished.png images to the src/main/resources/base/media... |
application-dev\ui\state-management\arkts-mvvm-V2.md | // src/main/ets/pages/3-Param.ets
@ComponentV2
struct TaskItem {
@Param taskName: string = '';
@Param @Once isFinish: boolean = false;
build() {
Row() {
// Add the finished.png and unfinished.png images to the src/main/resources/base/media directory. Otherwise, an error will be reported due to missing... |
application-dev\ui\state-management\arkts-mvvm-V2.md | // src/main/ets/pages/4-Event.ets
@ComponentV2
struct TaskItem {
@Param taskName: string = '';
@Param @Once isFinish: boolean = false;
@Event deleteTask: () => void = () => {};
build() {
Row() {
// Add the finished.png and unfinished.png images to the src/main/resources/base/media directory. Otherwi... |
application-dev\ui\state-management\arkts-mvvm-V2.md | // src/main/ets/pages/5-Repeat.ets
@ComponentV2
struct TaskItem {
@Param taskName: string = '';
@Param @Once isFinish: boolean = false;
@Event deleteTask: () => void = () => {};
build() {
Row() {
// Add the finished.png and unfinished.png images to the src/main/resources/base/media directory. Otherw... |
application-dev\ui\state-management\arkts-mvvm-V2.md | // src/main/ets/pages/6-ObservedV2Trace.ets
@ObservedV2
class Task {
taskName: string = '';
@Trace isFinish: boolean = false;
constructor (taskName: string, isFinish: boolean) {
this.taskName = taskName;
this.isFinish = isFinish;
}
}
@ComponentV2
struct TaskItem {
@Param task: Task = new Task('', f... |
application-dev\ui\state-management\arkts-mvvm-V2.md | // src/main/ets/pages/7-MonitorComputed.ets
@ObservedV2
class Task {
taskName: string = '';
@Trace isFinish: boolean = false;
constructor (taskName: string, isFinish: boolean) {
this.taskName = taskName;
this.isFinish = isFinish;
}
}
@ComponentV2
struct TaskItem {
@Param task: Task = new Task('', f... |
application-dev\ui\state-management\arkts-mvvm-V2.md | // src/main/ets/pages/8-AppStorageV2.ets
import { AppStorageV2 } from '@kit.ArkUI';
import { common, Want } from '@kit.AbilityKit';
import { Setting } from './SettingPage';
@ObservedV2
class Task {
taskName: string = '';
@Trace isFinish: boolean = false;
constructor (taskName: string, isFinish: boolean) {
... |
application-dev\ui\state-management\arkts-mvvm-V2.md | // SettingPage code of the SettingAbility.
import { AppStorageV2 } from '@kit.ArkUI';
import { common } from '@kit.AbilityKit';
@ObservedV2
export class Setting {
@Trace showCompletedTask: boolean = true;
}
@Entry
@ComponentV2
struct SettingPage {
@Local setting: Setting = AppStorageV2.connect(Setting, 'Setting',... |
application-dev\ui\state-management\arkts-mvvm-V2.md | // src/main/ets/pages/9-PersistenceV2.ets
import { AppStorageV2, PersistenceV2, Type } from '@kit.ArkUI';
import { common, Want } from '@kit.AbilityKit';
import { Setting } from './SettingPage';
import util from '@ohos.util';
@ObservedV2
class Task {
// The constructor is not implemented because @Type does not supp... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.