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