FA模型使用globalThis能够实现全局变量共享。使用参考:
app.ets中:
onCreate() {
console.info('Application onCreate')
globalThis.msg = 'test'
},
index.ets
@Entry
@Component
struct Index {
@State message: string = ''
aboutToAppear(){
this.message = globalThis.msg
}
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
}
.width('100%')
}
.height('100%')
}
}