diff --git a/zh-cn/application-dev/quick-start/arkts-mvvm.md b/zh-cn/application-dev/quick-start/arkts-mvvm.md index 1df7f939eb12e01c165ff1a207883ca1b4533385..ca4ef0d0aeba15e50322092cbdf580957a289191 100644 --- a/zh-cn/application-dev/quick-start/arkts-mvvm.md +++ b/zh-cn/application-dev/quick-start/arkts-mvvm.md @@ -621,7 +621,7 @@ struct Parent { ```ts class Outer { - innerArrayProp : ObservedArray; + innerArrayProp : ObservedArray = []; ... } ``` @@ -689,7 +689,7 @@ struct ViewB { (item: ClassA) => { ViewA({ label: `#${item.id}`, a: item }) }, - (item: ClassA) => item.id.toString() + (item: ClassA): string => { return item.id.toString(); } ) Divider().height(10) @@ -738,7 +738,7 @@ struct ViewB { @Component struct ViewA { - @Prop a: ClassA; + @Prop a: ClassA = new ClassA(0); label : string = "ViewA1"; build() { @@ -903,7 +903,7 @@ export class ObservedArray extends Array { @ObjectLink me : Person; @ObjectLink contacts : ObservedArray; - @State selectedPerson: Person = undefined; + @State selectedPerson: Person = new Person("", "", 0, "", []); aboutToAppear() { this.selectedPerson = this.me; @@ -919,7 +919,7 @@ export class ObservedArray extends Array { ForEach(this.contacts, (contact: Person) => { PersonView({ person: contact, phones: contact.phones as ObservedArray, selectedPerson: this.$selectedPerson }) }, - (contact: Person) => contact.id_ + (contact: Person): string => { return contact.id_; } ) Divider().height(8) @@ -1295,7 +1295,7 @@ export class ObservedArray extends Array { ForEach(this.contacts, (contact: Person) => { PersonView({ person: contact, phones: contact.phones as ObservedArray, selectedPerson: this.$selectedPerson }) }, - (contact: Person) => contact.id_ + (contact: Person): string => { return contact.id_; } ) Divider().height(8) diff --git a/zh-cn/application-dev/quick-start/arkts-state-management-best-practices.md b/zh-cn/application-dev/quick-start/arkts-state-management-best-practices.md index d52f598d46194893d98f6d2cf03e3613584f3352..0e45a6cd2747c6dddcd21fd7e9d98f0218abb152 100644 --- a/zh-cn/application-dev/quick-start/arkts-state-management-best-practices.md +++ b/zh-cn/application-dev/quick-start/arkts-state-management-best-practices.md @@ -507,8 +507,8 @@ incrSubCounter和setSubCounter都是同一个SubCounter的函数。在第一个 ```ts -@ObjectLink value:ParentCounter; -@ObjectLink subValue:SubCounter; +@ObjectLink value:ParentCounter = new ParentCounter(0); +@ObjectLink subValue:SubCounter = new SubCounter(0); ``` 该方法使得\@ObjectLink分别代理了ParentCounter和SubCounter的属性,这样对于这两个类的属性的变化都可以观察到,即都会对UI视图进行刷新。即使删除了上面所说的this.counter[0].incrCounter(),UI也会进行正确的刷新。 @@ -715,8 +715,8 @@ struct ParentComp { ```ts @Component struct CounterComp { - @Prop value: ParentCounter; - @Prop subValue: SubCounter; + @Prop value: ParentCounter = new ParentCounter(0); + @Prop subValue: SubCounter = new SubCounter(0); build() { Column({ space: 10 }) { Text(`this.subValue.counter: ${this.subValue.counter}`) @@ -948,8 +948,8 @@ build函数中更改应用状态的行为可能会比上面的示例更加隐蔽 ```ts -@State arr : Array<..> = [ ... ]; -ForEach(this.arr.sort().filter(....), +@State arr : Array<...> = [ ... ]; +ForEach(this.arr.sort().filter(...), item => { ... }) @@ -959,7 +959,7 @@ ForEach(this.arr.sort().filter(....), ```ts -ForEach(this.arr.filter(....).sort(), +ForEach(this.arr.filter(...).sort(), item => { ... }) diff --git a/zh-cn/application-dev/quick-start/arkts-watch.md b/zh-cn/application-dev/quick-start/arkts-watch.md index e607f0ff85eecf73de45c2d0a39696e32d30de8c..d683b300837f715ded2ec2c28c5e25155746dcca 100644 --- a/zh-cn/application-dev/quick-start/arkts-watch.md +++ b/zh-cn/application-dev/quick-start/arkts-watch.md @@ -60,7 +60,7 @@ ```ts @Component struct TotalView { - @Prop @Watch('onCountUpdated') count: number; + @Prop @Watch('onCountUpdated') count: number = 0; @State total: number = 0; // @Watch cb onCountUpdated(propName: string): void { diff --git a/zh-cn/application-dev/quick-start/in-app-hsp.md b/zh-cn/application-dev/quick-start/in-app-hsp.md index ec946f0d0ed437391649202d4065234283e4f1cd..d6b6a264c3ba64ed167630eafa71621f7560b514 100644 --- a/zh-cn/application-dev/quick-start/in-app-hsp.md +++ b/zh-cn/application-dev/quick-start/in-app-hsp.md @@ -145,6 +145,7 @@ export { nativeMulti } from './utils/nativeTest' ```ts // entry/src/main/ets/pages/index.ets import { Log, add, MyTitleBar, ResManager, nativeMulti } from "library" +import { BusinessError } from '@ohos.base'; @Entry @Component @@ -172,7 +173,7 @@ struct Index { .then(value => { console.log("getStringValue is " + value); }) - .catch(error => { + .catch((err: BusinessError) => { console.log("getStringValue promise error is " + error); }); }) diff --git a/zh-cn/application-dev/quick-start/start-with-ets-stage.md b/zh-cn/application-dev/quick-start/start-with-ets-stage.md index 04f63893d96bfd9ced996ed1f9d3f5c40b30142a..df621f42039411cf1ddb3159df48baf100cf5f4e 100644 --- a/zh-cn/application-dev/quick-start/start-with-ets-stage.md +++ b/zh-cn/application-dev/quick-start/start-with-ets-stage.md @@ -275,6 +275,7 @@ // Index.ets // 导入页面路由模块 import router from '@ohos.router'; + import { BusinessError } from '@ohos.base'; @Entry @Component @@ -306,7 +307,7 @@ // 跳转到第二页 router.pushUrl({ url: 'pages/Second' }).then(() => { console.info('Succeeded in jumping to the second page.') - }).catch((err) => { + }).catch((err: BusinessError) => { console.error(`Failed to jump to the second page.Code is ${err.code}, message is ${err.message}`) }) }) @@ -326,6 +327,7 @@ // Second.ets // 导入页面路由模块 import router from '@ohos.router'; + import { BusinessError } from '@ohos.base'; @Entry @Component @@ -358,7 +360,9 @@ router.back() console.info('Succeeded in returning to the first page.') } catch (err) { - console.error(`Failed to return to the first page.Code is ${err.code}, message is ${err.message}`) + let code = (err as BusinessError).code; + let message = (err as BusinessError).message; + console.error(`Failed to return to the first page.Code is ${code}, message is ${message}`) } }) }