diff --git a/pages/API/theme-change/theme-change.uvue b/pages/API/theme-change/theme-change.uvue index ab118218b8ad9bc3175136d4b14c40ad1d2ca573..0b7a168bafa71fa39df56bd6bd55a776c7d47728 100644 --- a/pages/API/theme-change/theme-change.uvue +++ b/pages/API/theme-change/theme-change.uvue @@ -45,11 +45,13 @@ }, methods: { bindOsThemeChange(): number { + //注册osTheme变化监听 return uni.onOsThemeChange(function(res: OsThemeChangeResult) { this.osTheme = res.osTheme }) }, bindAppThemeChange(): number { + //注册appTheme变化监听 return uni.onAppThemeChange(function(res: AppThemeChangeResult) { this.appTheme = res.appTheme }) @@ -84,6 +86,11 @@ }) this.osThemeChangeId = bindOsThemeChange() this.appThemeChangeId = bindAppThemeChange() + }, + onUnload() { + //注销监听 + uni.offAppThemeChange(this.appThemeChangeId) + uni.offOsThemeChange(this.osThemeChangeId) } }