-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Web #1000
base: web
Are you sure you want to change the base?
Web #1000
Conversation
@@ -25,7 +25,7 @@ sidebar: app_service_register | |||
|属性 |类型 | 默认值 | 描述 |触发时机| Web 态说明 | | |||
|---- | ---- | ---- | ---- | ---- | ---- | | |||
|其他 | Any || 开发者可以添加任意的函数或者数据到 Object 参数中, 用 this 可以访问。| ||| | |||
|onLogin | Function || 生命周期函数 -- 监听 web 态小程序登录成功(web 态小程序独有)| 当小程序初次登录成功后,会触发 onLogin (全局只触发一次)。|| | |||
|onLogin | Function || 生命周期函数 -- 监听 Web 态小程序登录成功( Web 态小程序独有)| 当小程序初次登录成功后,会触发 onLogin (全局只触发一次)。| 仅在 Web 态小程序中有效,百度 APP 端内小程序此生命周期不会触发| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个不需要新增 web 态说明列了。因为该行全是 web 态说明。新增列反而重复、而且困惑
|onLogin | Function || 生命周期函数 -- 监听 Web 态小程序登录成功,仅在 Web 态小程序中有效,百度 APP 端内小程序此生命周期不会触发| 当小程序初次登录成功后,会触发 onLogin (全局只触发一次)。|
- web小程序设计onLogin生命周期的原因:web小程序的登录不是在小程序内部页面进行的,是需要跳转登录页面进行登录,所以小程序未登录状态下进行swan.login的调用会进入登录页面进行登录所以会导致小程序的运行时环境会销毁,所以登录成功后开发者设置的success回调无法进行,所以需要设计一个时机(onLogin生命周期)把登录成功后的code给到开发者。 | ||
- 注意onLogin生命周期的触发时机在onLaunch之前,当时页面的dom还未ready。 | ||
- App 的 onLogin 生命周期是 Web 态小程序独有的且只有第一次登录成功后触发,百度 APP 端的小程序不会触发此生命周期。 | ||
- Web 态小程序设计 onLogin 生命周期的原因:Web 态小程序的登录不是在小程序内部页面进行的,是需要跳转登录页面进行登录,所以小程序未登录状态下进行 swan.login 的调用会进入登录页面进行登录所以会导致小程序的运行时环境会销毁,所以登录成功后开发者设置的 success 回调无法进行,所以需要设计一个时机( onLogin 生命周期)把登录成功后的 code 给到开发者。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
注意断句,注意减少重复的内容 避免困惑。
使用 onLogin 生命周期的意义:获取登录成功的 code。
原因:与端内小程序登录不同(在小程序页面内部登录),Web 态的登录需要跳转百度登录页面进行登录,登录成功后自动跳转原页面。该跳转过程会导致 Web 态的原执行上下文状态丢失,从而无法通过 swan.login 的成功回调获取登录成功的 code。因此必须通过 onLogin 生命周期获取该 code。
@@ -52,6 +52,9 @@ sidebar: app_service_register | |||
```js | |||
// app.js | |||
App({ | |||
onLogin(e) { | |||
// 使用 e.code 换取 session_key |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
修改 e 为 options
No description provided.