chenjun3_wd

早晚报标题,异步请求导致PaperTitleComponent传参时数据为空,使用provide/consume;consume所在componet不能声明@E…

…ntry,provide与consume名称要完全一致
... ... @@ -31,7 +31,8 @@ export struct MorningEveningPaperComponent {
// topicId: "10000002068",
// }
// } as MorningEveningPaperDTO
@State subTitle: string = ''
@Provide title: string = ''
@Provide subTitle: string = ''
async aboutToAppear() {
console.info(TAG, `aboutToAppear`)
... ... @@ -42,6 +43,7 @@ export struct MorningEveningPaperComponent {
try {
let pageInfoBean = await MorningEveningViewModel.getMorningEveningPageInfo("28927")
this.pageInfoBean = pageInfoBean;
this.title = this.pageInfoBean?.topicInfo?.title
let dateTime = DateTimeUtils.parseDate(this.pageInfoBean?.topicInfo?.topicDate ?? '', DateTimeUtils.PATTERN_DATE_HYPHEN);
this.subTitle = DateTimeUtils.formatDate(dateTime, PATTERN_DATE_CN_RN)
Logger.info(TAG, "pageInfoBean topicDate = " + this.pageInfoBean?.topicInfo?.topicDate)
... ... @@ -80,12 +82,13 @@ export struct MorningEveningPaperComponent {
.height('100%')
.margin({ left: 14, right: 14 })
PaperTitleComponent({
// title: this.morningEveningPaperDTO?.topicInfo?.title ?? "",
title: this.pageInfoBean?.topicInfo?.title ?? "",
// subtitle: this.morningEveningPaperDTO?.topicInfo?.topicDate ?? ''
subtitle: this.subTitle
})
PaperTitleComponent()
// PaperTitleComponent({
// // title: this.morningEveningPaperDTO?.topicInfo?.title ?? "",
// title: this.title ?? "",
// // subtitle: this.morningEveningPaperDTO?.topicInfo?.topicDate ?? ''
// subtitle: this.subTitle
// })
.margin({ left: 14, right: 14 })
}
.width('100%')
... ...
... ... @@ -3,11 +3,11 @@ import router from '@ohos.router';
/**
* 早晚报页面标题bar
*/
@Entry
// @Entry
@Component
export struct PaperTitleComponent {
@State title?: string = 'title'
@State subtitle?: string = 'subtitle'
@Consume title?: string
@Consume subTitle?: string
aboutToAppear() {
}
... ... @@ -31,7 +31,7 @@ export struct PaperTitleComponent {
.fontColor($r('app.color.white'))
.maxLines(1)
Text(this.subtitle ?? '')// Text('2024年\n1月16日')
Text(this.subTitle ?? '')// Text('2024年\n1月16日')
// .width(50)
.margin({ left: 5 })
.fontSize(12)
... ...