Skip to content
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

Open
wants to merge 2 commits into
base: web
Choose a base branch
from
Open

Web #1000

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions program-docs/docs/develop/framework/app_service_register.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ sidebar: app_service_register
|属性 |类型 | 默认值 | 描述 |触发时机| Web 态说明 |
|---- | ---- | ---- | ---- | ---- | ---- |
|其他 | Any || 开发者可以添加任意的函数或者数据到 Object 参数中, 用 this 可以访问。| |||
|onLogin | Function || 生命周期函数 -- 监听 web 态小程序登录成功(web 态小程序独有)| 当小程序初次登录成功后,会触发 onLogin (全局只触发一次)。||
|onLogin | Function || 生命周期函数 -- 监听 Web 态小程序登录成功( Web 态小程序独有)| 当小程序初次登录成功后,会触发 onLogin (全局只触发一次)。| 仅在 Web 态小程序中有效,百度 APP 端内小程序此生命周期不会触发|
Copy link
Collaborator

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 (全局只触发一次)。|

|onLaunch | Function || 生命周期函数 -- 监听小程序的初始化 。| 当小程序初始化完成时,会触发 onLaunch (全局只触发一次)。||
|onShow | Function ||生命周期函数 -- 监听小程序的显示 。| 当小程序初始化,或从后台进入前台显示,会触发 onShow 。|仅在小程序初始化时触发|
|onHide | Function || 生命周期函数 -- 监听小程序的隐藏 。| 当小程序从前台进入后台,会触发 onHide。 |暂不支持|
Expand All @@ -34,9 +34,9 @@ sidebar: app_service_register


**onLogin生命周期解释**
- app的onLogin生命周期是web小程序独有的且只有第一次登录成功后触发,百度App端的小程序没有此生命周期
- web小程序设计onLogin生命周期的原因:web小程序的登录不是在小程序内部页面进行的,是需要跳转登录页面进行登录,所以小程序未登录状态下进行swan.login的调用会进入登录页面进行登录所以会导致小程序的运行时环境会销毁,所以登录成功后开发者设置的success回调无法进行,所以需要设计一个时机(onLogin生命周期)把登录成功后的code给到开发者
- 注意onLogin生命周期的触发时机在onLaunch之前,当时页面的dom还未ready
- App 的 onLogin 生命周期是 Web 态小程序独有的且只有第一次登录成功后触发,百度 APP 端的小程序不会触发此生命周期
- Web 态小程序设计 onLogin 生命周期的原因:Web 态小程序的登录不是在小程序内部页面进行的,是需要跳转登录页面进行登录,所以小程序未登录状态下进行 swan.login 的调用会进入登录页面进行登录所以会导致小程序的运行时环境会销毁,所以登录成功后开发者设置的 success 回调无法进行,所以需要设计一个时机( onLogin 生命周期)把登录成功后的 code 给到开发者
Copy link
Collaborator

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。

- 注意 onLogin 生命周期的触发时机在 onLaunch 之前,当时页面的 dom 还未 ready

**名词解释:**
前台、后台:当用户点击右上角的关闭,或者按了设备的 Home 键离开智能小程序,智能小程序没有直接销毁,而是进入到了后台;当再次进入智能小程序,又会从后台进入前台。
Expand All @@ -52,6 +52,9 @@ sidebar: app_service_register
```js
// app.js
App({
onLogin(e) {
// 使用 e.code 换取 session_key
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修改 e 为 options

},
onLaunch(options) {
// Do something initial when launch.
},
Expand Down