Skip to content

Commit

Permalink
feat(mp): 添加 patchMiniProgram
Browse files Browse the repository at this point in the history
  • Loading branch information
fjc0k committed Aug 25, 2020
1 parent f102307 commit b6d0669
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/mp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export * from './getTopBarInfo'
export * from './miniProgramConfig'
export * from './navigatePageBack'
export * from './navigatePageTo'
export * from './patchMiniProgram'
export * from './redirectPageTo'
export * from './submit'
// @endindex
21 changes: 21 additions & 0 deletions src/mp/patchMiniProgram.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { ensureInMiniProgram } from './ensureInMiniProgram'

/**
* 给各个品牌小程序打补丁以期行为与微信保持一致。
*/
export function patchMiniProgram() {
ensureInMiniProgram(mp => {
if (mp.$brand === '支付宝') {
// 支持通过 options 获取页面参数
const originalPage = Page
Page = function (options) {
const onLoad = options.onLoad
options.onLoad = function (query) {
;(this as any).options = query
onLoad && onLoad.call(this, query)
}
originalPage(options)
}
}
})
}

0 comments on commit b6d0669

Please sign in to comment.