#鸿蒙通关秘籍#如何在HarmonyOS NEXT中处理自动登录逻辑?

HarmonyOS
2024-11-27 11:20:15
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
hm673ff058c261d

自动登录逻辑由aboutToAppear方法实现,在用户选择记住密码的情况下,从本地存储读取账号和密码。如果账号和密码存在且stopLogin参数为false,则自动调用handleLogin进行登录。

async aboutToAppear() {
  const params = router.getParams();
  this.stopLogin = params.stopLogin || false;
  this.rememberPassword = await PreferencesUtils.get('rememberPassword');

  if (this.rememberPassword) {
    this.account = await PreferencesUtils.get("account");
    this.password = await PreferencesUtils.get("password");
  }

  if (this.account && this.password && !this.stopLogin) {
    this.handleLogin();
  }
}
分享
微博
QQ
微信
回复
2024-11-27 12:10:13
相关问题