Skip to content

Commit

Permalink
fix(Wechat): invoke 时微信 JSSDK 可能尚在加载
Browse files Browse the repository at this point in the history
  • Loading branch information
fjc0k committed May 22, 2019
1 parent a28c715 commit 263c557
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/Wechat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,19 +402,18 @@ export class Wechat {
*/
invoke(jsApi: WechatJsApi, params: Record<string, any> = {}): Promise<any> {
return new Promise((resolve, reject) => {
if (typeof wx === 'undefined') return reject('请先引入微信 JSSDK')
if (!wx[jsApi]) return reject(`wx.${jsApi} 不可用`)
const invoke = () => {
if (!wx[jsApi]) return reject(`wx.${jsApi} 不可用`)
wx[jsApi]({
...params,
success: resolve,
fail: reject,
})
}
if (this.ready) {
invoke()
} else {
if (typeof wx === 'undefined' || !this.ready) {
this.bus.once('ready', invoke)
} else {
invoke()
}
})
}
Expand Down

0 comments on commit 263c557

Please sign in to comment.