heymie
Results
2
comments of
heymie
getCurrentInstance的实现机制是基于onShow和onHide来进行赋值和置空,在生命周期可能错乱时,会导致异常。 这也是官方说的慎用getCurrentInstance的原因。 类似场景还有如果微信小程序被切入后台时,延时执行的代码在使用getCurrentInstance API时,也会中招。
以往的settimeout的时间点不好把握,体验较差。 最近组内小伙伴提出一个比较好的方案。 可以监听页面的onshow加上支付结果回调,通过promise.all的方式,等待两个都执行后,最终抛回支付结果。 示例代码如下: ` const _onShowEventId = getCurrentInstance()?.router?.onShow const _onShowPromise = () => { return new Promise((_resolve) => { if (_onShowEventId) { eventCenter.once(_onShowEventId,() => { _resolve(true) }) } else...