中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
本文原创发布在华为开发者社区。
本示例使用@CustomDialog实现隐私弹窗,使用AppStorage+PersistentStorage保存用户是否同意。
实现隐私弹窗源码链接
使用@CustomDialog实现隐私弹窗,使用AppStorage+PersistentStorage保存用户是否同意。核心代码如下:
Button('同意') .margin(5) .width(250) .backgroundColor($r('app.color.button_back_color')) .fontColor($r('sys.color.comp_background_list_card')) .onClick(() => { if (this.controller != undefined) { this.controller.close() } // 存储用户同意 AppStorage.setOrCreate('isAgreed', true) PersistentStorage.persistProp('isAgreed', true) router.replaceUrl({ url: 'pages/MainPage' }); }) .height(40)
微信扫码分享