未验证 提交 2623e1a5 编写于 作者: O openharmony_ci 提交者: Gitee

!23597 Rectify the arkts syntax of qs on monthly

Merge pull request !23597 from 189******51/monthly_20230815
......@@ -101,7 +101,7 @@ class PointVector extends Array<Point> implements AnimatableArithmetic<PointVect
let result = new PointVector([])
const len = Math.min(this.length, rhs.length)
for (let i = 0; i < len; i++) {
result.push(this[i].plus(rhs[i]))
result.push((this as Array<Point>)[i].plus((rhs as Array<Point>)[i]))
}
return result
}
......@@ -109,14 +109,14 @@ class PointVector extends Array<Point> implements AnimatableArithmetic<PointVect
let result = new PointVector([])
const len = Math.min(this.length, rhs.length)
for (let i = 0; i < len; i++) {
result.push(this[i].subtract(rhs[i]))
result.push((this as Array<Point>)[i].subtract((rhs as Array<Point>)[i]))
}
return result
}
multiply(scale: number): PointVector {
let result = new PointVector([])
for (let i = 0; i < this.length; i++) {
result.push(this[i].multiply(scale))
result.push((this as Array<Point>)[i].multiply(scale))
}
return result
}
......@@ -125,14 +125,14 @@ class PointVector extends Array<Point> implements AnimatableArithmetic<PointVect
return false
}
for (let i = 0; i < this.length; i++) {
if (!this[i].equals(rhs[i])) {
if (!(this as Array<Point>)[i].equals((rhs as Array<Point>)[i])) {
return false
}
}
return true
}
get():Array<[x: number, y: number]> {
let result = []
get(): Array<Object[]> {
let result: Array<Object[]> = []
this.forEach(p => result.push([p.x, p.y]))
return result
}
......
......@@ -144,21 +144,22 @@ AppStorage是单例,它的所有API都是静态的,使用方法类似于中L
```ts
AppStorage.SetOrCreate('PropA', 47);
let storage: LocalStorage = new LocalStorage({ 'PropA': 17 });
let propA: number = AppStorage.Get('PropA') // propA in AppStorage == 47, propA in LocalStorage == 17
var link1: SubscribedAbstractProperty<number> = AppStorage.Link('PropA'); // link1.get() == 47
var link2: SubscribedAbstractProperty<number> = AppStorage.Link('PropA'); // link2.get() == 47
var prop: SubscribedAbstractProperty<number> = AppStorage.Prop('PropA'); // prop.get() = 47
let storage: LocalStorage = new LocalStorage();
storage['PropA'] = 17;
let propA: number | undefined = AppStorage.Get('PropA') // propA in AppStorage == 47, propA in LocalStorage == 17
let link1: SubscribedAbstractProperty<number> = AppStorage.Link('PropA'); // link1.get() == 47
let link2: SubscribedAbstractProperty<number> = AppStorage.Link('PropA'); // link2.get() == 47
let prop: SubscribedAbstractProperty<number> = AppStorage.Prop('PropA'); // prop.get() = 47
link1.set(48); // two-way sync: link1.get() == link2.get() == prop.get() == 48
prop.set(1); // one-way sync: prop.get()=1; but link1.get() == link2.get() == 48
link1.set(49); // two-way sync: link1.get() == link2.get() == prop.get() == 49
storage.get('PropA') // == 17
storage.get<number>('PropA') // == 17
storage.set('PropA', 101);
storage.get('PropA') // == 101
storage.get<number>('PropA') // == 101
AppStorage.Get('PropA') // == 49
AppStorage.Get<number>('PropA') // == 49
link1.get() // == 49
link2.get() // == 49
prop.get() // == 49
......@@ -172,7 +173,8 @@ prop.get() // == 49
```ts
AppStorage.SetOrCreate('PropA', 47);
let storage = new LocalStorage({ 'PropA': 48 });
let storage = new LocalStorage();
storage['PropA'] = 48;
@Entry(storage)
@Component
......@@ -242,8 +244,13 @@ struct Gallery2 {
export struct TapImage {
@StorageLink('tapIndex') @Watch('onTapIndexChange') tapIndex: number = -1;
@State tapColor: Color = Color.Black;
private index: number;
private uri: Resource;
private index: number = 0;
private uri: Resource = {
id: 0,
type: 0,
moduleName: "",
bundleName: ""
};
// 判断是否被选中
onTapIndexChange() {
......@@ -313,9 +320,9 @@ struct Gallery2 {
if (this.preIndex === item.id) {
return
}
var innerEvent = { eventId: item.id }
let innerEvent: emitter.InnerEvent = { eventId: item.id }
// 选中态:黑变红
var eventData = {
let eventData: emitter.EventData = {
data: {
"colorTag": 1
}
......@@ -324,9 +331,9 @@ struct Gallery2 {
if (this.preIndex != -1) {
console.info(`preIndex: ${this.preIndex}, index: ${item.id}, black`)
var innerEvent = { eventId: this.preIndex }
let innerEvent: emitter.InnerEvent = { eventId: this.preIndex }
// 取消选中态:红变黑
var eventData = {
let eventData: emitter.EventData = {
data: {
"colorTag": 0
}
......@@ -335,7 +342,6 @@ struct Gallery2 {
}
this.preIndex = item.id
})
}, (item: ViewData) => JSON.stringify(item))
}.columnsTemplate('1fr 1fr')
}
......@@ -346,17 +352,26 @@ struct Gallery2 {
@Component
export struct TapImage {
@State tapColor: Color = Color.Black;
private index: number;
private uri: Resource;
private index: number = 0;
private uri: Resource = {
id: 0,
type: 0,
moduleName: "",
bundleName: ""
};
onTapIndexChange(colorTag: emitter.EventData) {
this.tapColor = colorTag.data.colorTag ? Color.Red : Color.Black
if (colorTag.data != null) {
this.tapColor = colorTag.data.colorTag ? Color.Red : Color.Black
}
}
aboutToAppear() {
//定义事件ID
var innerEvent = { eventId: this.index }
emitter.on(innerEvent, this.onTapIndexChange.bind(this))
let innerEvent: emitter.InnerEvent = { eventId: this.index }
emitter.on(innerEvent, data => {
this.onTapIndexChange(data)
})
}
build() {
......@@ -414,8 +429,13 @@ struct Gallery2 {
export struct TapImage {
@StorageLink('tapIndex') tapIndex: number = -1;
@State tapColor: Color = Color.Black;
private index: number;
private uri: Resource;
private index: number = 0;
private uri: Resource = {
id: 0,
type: 0,
moduleName: "",
bundleName: ""
};
build() {
Column() {
......
......@@ -77,13 +77,22 @@ MyGlobalBuilderFunction()
```ts
ABuilder( $$ : { paramA1: string, paramB1 : string } );
class ABuilderParam {
paramA1: string = ''
paramB1: string = ''
}
ABuilder($$ : ABuilderParam);
```
```ts
@Builder function ABuilder($$: { paramA1: string }) {
class ABuilderParam {
paramA1: string = ''
}
@Builder function ABuilder($$: ABuilderParam) {
Row() {
Text(`UseStateVarByReference: ${$$.paramA1} `)
}
......
......@@ -34,30 +34,34 @@
- 用父组件自定义构建函数初始化子组件\@BuildParam装饰的方法。
```ts
@Component
struct Child {
@BuilderParam aBuilder0: () => void;
@Component
struct Child {
@Builder componentBuilder() {
Text(`Parent builder `)
}
build() {
Column() {
this.aBuilder0()
}
@BuilderParam aBuilder0: () => void = this.componentBuilder;
build() {
Column() {
this.aBuilder0()
}
}
}
@Entry
@Component
struct Parent {
@Builder componentBuilder() {
Text(`Parent builder `)
}
@Entry
@Component
struct Parent {
@Builder componentBuilder() {
Text(`Parent builder `)
}
build() {
Column() {
Child({ aBuilder0: this.componentBuilder })
}
build() {
Column() {
Child({ aBuilder0: this.componentBuilder })
}
}
}
```
......@@ -70,36 +74,40 @@
> 开发者谨慎使用bind改变函数调用的上下文,可能会使this指向混乱。
```ts
@Component
struct Child {
label: string = `Child`
@BuilderParam aBuilder0: () => void;
@BuilderParam aBuilder1: () => void;
build() {
Column() {
this.aBuilder0()
this.aBuilder1()
}
}
@Component
struct Child {
@Builder componentBuilder() {
Text(`Child builder `)
}
@Entry
@Component
struct Parent {
label: string = `Parent`
label: string = `Child`
@BuilderParam aBuilder0: () => void = this.componentBuilder;
@BuilderParam aBuilder1: () => void = this.componentBuilder;
@Builder componentBuilder() {
Text(`${this.label}`)
build() {
Column() {
this.aBuilder0()
this.aBuilder1()
}
}
}
build() {
Column() {
this.componentBuilder()
Child({ aBuilder0: this.componentBuilder, aBuilder1: this.componentBuilder.bind(this) })
}
@Entry
@Component
struct Parent {
label: string = `Parent`
@Builder componentBuilder() {
Text(`${this.label}`)
}
build() {
Column() {
this.componentBuilder()
Child({ aBuilder0: this.componentBuilder, aBuilder1: this.componentBuilder })
}
}
}
```
......@@ -112,7 +120,11 @@
```ts
@Builder function GlobalBuilder1($$ : {label: string }) {
class GlobalBuilderParam {
label: string = ""
}
@Builder function GlobalBuilder1($$ : GlobalBuilderParam) {
Text($$.label)
.width(400)
.height(50)
......@@ -121,11 +133,15 @@
@Component
struct Child {
@Builder componentBuilder() {
Text(`Child builder `)
}
label: string = 'Child'
// 无参数类,指向的componentBuilder也是无参数类型
@BuilderParam aBuilder0: () => void;
@BuilderParam aBuilder0: () => void = this.componentBuilder;
// 有参数类型,指向的GlobalBuilder1也是有参数类型的方法
@BuilderParam aBuilder1: ($$ : { label : string}) => void;
@BuilderParam aBuilder1: ($$ : GlobalBuilderParam) => void = this.componentBuilder;
build() {
Column() {
......@@ -167,10 +183,17 @@ struct Parent {
```ts
// xxx.ets
class CustomContainerParam {
header: string = '';
}
@Component
struct CustomContainer {
@Prop header: string;
@BuilderParam closer: () => void
@Builder componentCloser() {
Text(`Custom closer `)
}
@Prop header: string = '';
@BuilderParam closer: () => void = this.componentCloser;
build() {
Column() {
......@@ -194,12 +217,15 @@ struct CustomContainer {
@Component
struct CustomContainerUser {
@State text: string = 'header';
param: CustomContainerParam = {
header: this.text
};
build() {
Column() {
// 创建CustomContainer,在创建CustomContainer时,通过其后紧跟一个大括号“{}”形成尾随闭包
// 作为传递给子组件CustomContainer @BuilderParam closer: () => void的参数
CustomContainer({ header: this.text }) {
CustomContainer(this.param) {
Column() {
specificParam('testA', 'testB')
}.backgroundColor(Color.Yellow)
......
......@@ -42,15 +42,23 @@ HelloComponent可以在其他自定义组件中的build()函数中多次创建
```ts
class HelloComponentParam {
message: string = ""
}
@Entry
@Component
struct ParentComponent {
param: HelloComponentParam = {
message: 'Hello, World!'
}
build() {
Column() {
Text('ArkUI message')
HelloComponent({ message: 'Hello, World!' });
HelloComponent(param);
Divider()
HelloComponent({ message: '你好!' });
HelloComponent(param);
}
}
}
......
......@@ -35,7 +35,7 @@ Environment是ArkUI框架在应用程序启动时创建的单例对象。它为A
```ts
// 将设备languageCode存入AppStorage中
Environment.EnvProp('languageCode', 'en');
let enable = AppStorage.Get('languageCode');
let enable: undefined = AppStorage.Get<undefined>('languageCode');
@Entry
@Component
......
......@@ -64,27 +64,27 @@
- \@Extend装饰的方法的参数可以为function,作为Event事件的句柄。
```ts
@Extend(Text) function makeMeClick(onClick: () => void) {
.backgroundColor(Color.Blue)
.onClick(onClick)
}
@Extend(Text) function makeMeClick(onClick: () => void) {
.backgroundColor(Color.Blue)
.onClick(onClick)
}
@Entry
@Component
struct FancyUse {
@State label: string = 'Hello World';
@Entry
@Component
struct FancyUse {
@State label: string = 'Hello World';
onClickHandler() {
this.label = 'Hello ArkUI';
}
onClickHandler() {
this.label = 'Hello ArkUI';
}
build() {
Row({ space: 10 }) {
Text(`${this.label}`)
.makeMeClick(this.onClickHandler.bind(this))
}
build() {
Row({ space: 10 }) {
Text(`${this.label}`)
.makeMeClick(this.onClickHandler.bind(this))
}
}
}
```
- \@Extend的参数可以为[状态变量](arkts-state-management-overview.md),当状态变量改变时,UI可以正常的被刷新渲染。
......
......@@ -227,10 +227,10 @@ struct Parent {
Column() {
Child({ items: $arr })
ForEach(this.arr,
item => {
(item: void) => {
Text(`${item}`)
},
item => item.toString()
(item: ForEachInterface) => item.toString()
)
}
}
......
......@@ -167,11 +167,12 @@ LocalStorage根据与\@Component装饰的组件的同步类型不同,提供了
```ts
let storage = new LocalStorage({ 'PropA': 47 }); // 创建新实例并使用给定对象初始化
let propA = storage.get('PropA') // propA == 47
let link1 = storage.link('PropA'); // link1.get() == 47
let link2 = storage.link('PropA'); // link2.get() == 47
let prop = storage.prop('PropA'); // prop.get() = 47
let storage = new LocalStorage(); // 创建新实例并使用给定对象初始化
storage['PropA'] = 47
let propA = storage.get<number>('PropA') // propA == 47
let link1 = storage.link<number>('PropA'); // link1.get() == 47
let link2 = storage.link<number>('PropA'); // link2.get() == 47
let prop = storage.prop<number>('PropA'); // prop.get() = 47
link1.set(48); // two-way sync: link1.get() == link2.get() == prop.get() == 48
prop.set(1); // one-way sync: prop.get()=1; but link1.get() == link2.get() == 48
link1.set(49); // two-way sync: link1.get() == link2.get() == prop.get() == 49
......@@ -191,36 +192,37 @@ link1.set(49); // two-way sync: link1.get() == link2.get() == prop.get() == 49
- \@LocalStorageLink绑定LocalStorage对给定的属性,建立双向数据同步。
```ts
// 创建新实例并使用给定对象初始化
let storage = new LocalStorage({ 'PropA': 47 });
@Component
struct Child {
// @LocalStorageLink变量装饰器与LocalStorage中的'ProA'属性建立双向绑定
@LocalStorageLink('PropA') storLink2: number = 1;
build() {
Button(`Child from LocalStorage ${this.storLink2}`)
// 更改将同步至LocalStorage中的'ProA'以及Parent.storLink1
.onClick(() => this.storLink2 += 1)
}
// 创建新实例并使用给定对象初始化
let storage = new LocalStorage();
storage['PropA'] = 47;
@Component
struct Child {
// @LocalStorageLink变量装饰器与LocalStorage中的'ProA'属性建立双向绑定
@LocalStorageLink('PropA') storLink2: number = 1;
build() {
Button(`Child from LocalStorage ${this.storLink2}`)
// 更改将同步至LocalStorage中的'ProA'以及Parent.storLink1
.onClick(() => this.storLink2 += 1)
}
// 使LocalStorage可从@Component组件访问
@Entry(storage)
@Component
struct CompA {
// @LocalStorageLink变量装饰器与LocalStorage中的'ProA'属性建立双向绑定
@LocalStorageLink('PropA') storLink1: number = 1;
build() {
Column({ space: 15 }) {
Button(`Parent from LocalStorage ${this.storLink1}`) // initial value from LocalStorage will be 47, because 'PropA' initialized already
.onClick(() => this.storLink1 += 1)
// @Component子组件自动获得对CompA LocalStorage实例的访问权限。
Child()
}
}
// 使LocalStorage可从@Component组件访问
@Entry(storage)
@Component
struct CompA {
// @LocalStorageLink变量装饰器与LocalStorage中的'ProA'属性建立双向绑定
@LocalStorageLink('PropA') storLink1: number = 1;
build() {
Column({ space: 15 }) {
Button(`Parent from LocalStorage ${this.storLink1}`) // initial value from LocalStorage will be 47, because 'PropA' initialized already
.onClick(() => this.storLink1 += 1)
// @Component子组件自动获得对CompA LocalStorage实例的访问权限。
Child()
}
}
}
```
......@@ -233,37 +235,39 @@ link1.set(49); // two-way sync: link1.get() == link2.get() == prop.get() == 49
- Child组件中,Text绑定的storProp2 依旧显示47。
```ts
// 创建新实例并使用给定对象初始化
let storage = new LocalStorage({ 'PropA': 47 });
// 使LocalStorage可从@Component组件访问
@Entry(storage)
@Component
struct CompA {
// @LocalStorageProp变量装饰器与LocalStorage中的'ProA'属性建立单向绑定
@LocalStorageProp('PropA') storProp1: number = 1;
build() {
Column({ space: 15 }) {
// 点击后从47开始加1,只改变当前组件显示的storProp1,不会同步到LocalStorage中
Button(`Parent from LocalStorage ${this.storProp1}`)
.onClick(() => this.storProp1 += 1)
Child()
}
// 创建新实例并使用给定对象初始化
let storage = new LocalStorage();
storage['PropA'] = 47;
// 使LocalStorage可从@Component组件访问
@Entry(storage)
@Component
struct CompA {
// @LocalStorageProp变量装饰器与LocalStorage中的'ProA'属性建立单向绑定
@LocalStorageProp('PropA') storProp1: number = 1;
build() {
Column({ space: 15 }) {
// 点击后从47开始加1,只改变当前组件显示的storProp1,不会同步到LocalStorage中
Button(`Parent from LocalStorage ${this.storProp1}`)
.onClick(() => this.storProp1 += 1)
Child()
}
}
}
@Component
struct Child {
// @LocalStorageProp变量装饰器与LocalStorage中的'ProA'属性建立单向绑定
@LocalStorageProp('PropA') storProp2: number = 2;
@Component
struct Child {
// @LocalStorageProp变量装饰器与LocalStorage中的'ProA'属性建立单向绑定
@LocalStorageProp('PropA') storProp2: number = 2;
build() {
Column({ space: 15 }) {
// 当CompA改变时,当前storProp2不会改变,显示47
Text(`Parent from LocalStorage ${this.storProp2}`)
}
build() {
Column({ space: 15 }) {
// 当CompA改变时,当前storProp2不会改变,显示47
Text(`Parent from LocalStorage ${this.storProp2}`)
}
}
}
```
......@@ -274,9 +278,10 @@ link1.set(49); // two-way sync: link1.get() == link2.get() == prop.get() == 49
```ts
// 构造LocalStorage实例
let storage = new LocalStorage({ 'PropA': 47 });
let storage = new LocalStorage();
storage['PropA'] = 47;
// 调用link9+接口构造'PropA'的双向同步数据,linkToPropA 是全局变量
let linkToPropA = storage.link('PropA');
let linkToPropA = storage.link<number>('PropA');
@Entry(storage)
@Component
......@@ -288,7 +293,7 @@ struct CompA {
build() {
Column() {
Text(`incr @LocalStorageLink variable`)
// 点击“incr @LocalStorageLink variable”,this.storLink加1,改变同步回storage,全局变量linkToPropA也会同步改变
// 点击“incr @LocalStorageLink variable”,this.storLink加1,改变同步回storage,全局变量linkToPropA也会同步改变
.onClick(() => this.storLink += 1)
......@@ -317,63 +322,71 @@ Child自定义组件中的变化:
1. playCountLink的刷新会同步回LocalStorage,并且引起兄弟组件和父组件相应的刷新。
```ts
let storage = new LocalStorage({ countStorage: 1 });
@Component
struct Child {
// 子组件实例的名字
label: string = 'no name';
// 和LocalStorage中“countStorage”的双向绑定数据
@LocalStorageLink('countStorage') playCountLink: number = 0;
build() {
Row() {
Text(this.label)
.width(50).height(60).fontSize(12)
Text(`playCountLink ${this.playCountLink}: inc by 1`)
.onClick(() => {
this.playCountLink += 1;
})
.width(200).height(60).fontSize(12)
}.width(300).height(60)
}
}
@Entry(storage)
@Component
struct Parent {
@LocalStorageLink('countStorage') playCount: number = 0;
build() {
Column() {
Row() {
Text('Parent')
.width(50).height(60).fontSize(12)
Text(`playCount ${this.playCount} dec by 1`)
.onClick(() => {
this.playCount -= 1;
})
.width(250).height(60).fontSize(12)
}.width(300).height(60)
Row() {
Text('LocalStorage')
.width(50).height(60).fontSize(12)
Text(`countStorage ${this.playCount} incr by 1`)
.onClick(() => {
storage.set<number>('countStorage', 1 + storage.get<number>('countStorage'));
})
.width(250).height(60).fontSize(12)
}.width(300).height(60)
Child({ label: 'ChildA' })
Child({ label: 'ChildB' })
Text(`playCount in LocalStorage for debug ${storage.get<number>('countStorage')}`)
.width(300).height(60).fontSize(12)
}
}
}
class Data {
countStorage: number = 0;
}
let data: Data = { countStorage: 1 }
let storage = new LocalStorage(data);
@Component
struct Child {
// 子组件实例的名字
label: string = 'no name';
// 和LocalStorage中“countStorage”的双向绑定数据
@LocalStorageLink('countStorage') playCountLink: number = 0;
build() {
Row() {
Text(this.label)
.width(50).height(60).fontSize(12)
Text(`playCountLink ${this.playCountLink}: inc by 1`)
.onClick(() => {
this.playCountLink += 1;
})
.width(200).height(60).fontSize(12)
}.width(300).height(60)
}
}
@Entry(storage)
@Component
struct Parent {
@LocalStorageLink('countStorage') playCount: number = 0;
build() {
Column() {
Row() {
Text('Parent')
.width(50).height(60).fontSize(12)
Text(`playCount ${this.playCount} dec by 1`)
.onClick(() => {
this.playCount -= 1;
})
.width(250).height(60).fontSize(12)
}.width(300).height(60)
Row() {
Text('LocalStorage')
.width(50).height(60).fontSize(12)
Text(`countStorage ${this.playCount} incr by 1`)
.onClick(() => {
let countStorage: number | undefined = storage.get<number>('countStorage');
if (countStorage != undefined){
countStorage += 1;
storage.set<number>('countStorage', countStorage);
}
})
.width(250).height(60).fontSize(12)
}.width(300).height(60)
Child({ label: 'ChildA' })
Child({ label: 'ChildB' })
Text(`playCount in LocalStorage for debug ${storage.get<number>('countStorage')}`)
.width(300).height(60).fontSize(12)
}
}
}
```
......@@ -388,11 +401,10 @@ import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';
export default class EntryAbility extends UIAbility {
storage: LocalStorage = new LocalStorage({
'PropA': 47
});
storage: LocalStorage = new LocalStorage();
onWindowStageCreate(windowStage: window.WindowStage) {
this.storage['PropA'] = 47;
windowStage.loadContent('pages/Index', this.storage);
}
}
......
......@@ -126,7 +126,7 @@ this.b.a.c = 5
```ts
@Observed
class DateClass extends Date {
constructor(args: any) {
constructor(args: number | string) {
super(args)
}
}
......@@ -343,10 +343,10 @@ struct ViewB {
build() {
Column() {
ForEach(this.arrA,
(item) => {
(item: ClassA) => {
ViewA({ label: `#${item.id}`, a: item })
},
(item) => item.id.toString()
(item: ClassA) => item.id.toString()
)
// 使用@State装饰的数组的数组项初始化@ObjectLink,其中数组项是被@Observed装饰的ClassA的实例
ViewA({ label: `ViewA this.arrA[first]`, a: this.arrA[0] })
......@@ -419,11 +419,11 @@ struct ItemPage {
.width(100).height(100)
ForEach(this.itemArr,
item => {
(item: string | Resource) => {
Text(item)
.width(100).height(100)
},
item => item
(item: string) => item
)
}
}
......@@ -439,14 +439,14 @@ struct IndexPage {
ItemPage({ itemArr: this.arr[0] })
ItemPage({ itemArr: this.arr[1] })
ItemPage({ itemArr: this.arr[2] })
Divider()
ForEach(this.arr,
itemArr => {
(itemArr: StringArray) => {
ItemPage({ itemArr: itemArr })
},
itemArr => itemArr[0]
(itemArr: string) => itemArr[0]
)
Divider()
......@@ -454,7 +454,7 @@ struct IndexPage {
Button('update')
.onClick(() => {
console.error('Update all items in arr');
if (this.arr[0][0] !== undefined) {
if ((this.arr[0] as Array<String>)[0] !== undefined) {
// 正常情况下需要有一个真实的ID来与ForEach一起使用,但此处没有
// 因此需要确保推送的字符串是唯一的。
this.arr[0].push(`${this.arr[0].slice(-1).pop()}${this.arr[0].slice(-1).pop()}`);
......
......@@ -40,7 +40,7 @@ PersistentStorage和UIContext相关联,需要在[UIContext](../reference/apis/
2. 在AppStorage获取对应属性:
```ts
AppStorage.Get('aProp'); // returns 47
AppStorage.Get<number>('aProp'); // returns 47
```
或在组件内部定义:
......
......@@ -118,7 +118,7 @@ this.title.push('3')
```ts
@Component
struct DateComponent {
@Prop selectedDate: Date;
@Prop selectedDate: Date = new Date('');
build() {
Column() {
......@@ -198,7 +198,7 @@ ParentComponent的状态变量countDownStartValue的变化将重置CountDownComp
```ts
@Component
struct CountDownComponent {
@Prop count: number;
@Prop count: number = 0;
costOfOneAttempt: number = 1;
build() {
......@@ -370,7 +370,7 @@ class Book {
@Component
struct ReaderComp {
@Prop book: Book;
@Prop book: Book = new Book("", 0);
build() {
Row() {
......@@ -497,7 +497,7 @@ class Book {
```ts
@Component
struct MyComponent {
@Prop customCounter: number;
@Prop customCounter: number = 0;
@Prop customCounter2: number = 5;
build() {
......@@ -588,10 +588,10 @@ struct Parent {
build() {
Column() {
Button('change')
.onClick(() => {
this.votes.name = "aaaaa"
this.votes.a.title = "wwwww"
})
.onClick(() => {
this.votes.name = "aaaaa"
this.votes.a.title = "wwwww"
})
Child({ vote: this.votes })
}
......@@ -600,33 +600,33 @@ struct Parent {
@Component
struct Child {
@Prop vote: ClassB
@Prop vote: ClassB = new ClassB('', new ClassA(''));
build() {
Column() {
Column() {
Text(this.vote.name).fontSize(36).fontColor(Color.Red).margin(50)
.onClick(() => {
this.vote.name = 'Bye'
})
Text(this.vote.a.title).fontSize(36).fontColor(Color.Blue)
.onClick(() => {
this.vote.a.title = "openHarmony"
})
Child1({vote1:this.vote.a})
Text(this.vote.name).fontSize(36).fontColor(Color.Red).margin(50)
.onClick(() => {
this.vote.name = 'Bye'
})
Text(this.vote.a.title).fontSize(36).fontColor(Color.Blue)
.onClick(() => {
this.vote.a.title = "openHarmony"
})
Child1({vote1:this.vote.a})
}
}
}
}
@Component
struct Child1 {
@Prop vote1: ClassA
@Prop vote1: ClassA = new ClassA('');
build() {
Column() {
Text(this.vote1.title).fontSize(36).fontColor(Color.Red).margin(50)
.onClick(() => {
this.vote1.title = 'Bye Bye'
})
Text(this.vote1.title).fontSize(36).fontColor(Color.Red).margin(50)
.onClick(() => {
this.vote1.title = 'Bye Bye'
})
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册