guankaishe

Results 57 comments of guankaishe

```js A({ config: { extendPageBefore: function (def, { fns }) { def.someReusedMethod = function () { // TODO } } } }); ```

一般预加载是使用提前生成Promise实例执行加载流程,只要在Promise的回调后就不需要关心异步逻辑是进行中 or 完成

```js // 页面index Page.P('index', { clickToDetail() { this.$preload('detail') } }) ``` ```js // 页面detail Page.P('detail', { onPreload() { this.$put('detail_preload_fetch', this.fetch()) }, onLoad() { ;(this.$take('detail_preload_fetch')||this.fetch()).then(data=>{ console.log(data) // do somthing }) },...

中间利用的是小程序页面实例化的时间差,不管怎样,请求都是被提前发起了,必然会起到优化效果

能确认 `this.$on` 是在 `this.$emit`之前执行吗

> 通过这样挂载后 在页面中使用this.$test() 为什么会出现is not a function 能展示下在哪个生命周期使用,与及完整的报错信息吗

`extendPageBefore`是在[config](https://github.com/tvfe/wxpage#%E7%A8%8B%E5%BA%8F-%E9%85%8D%E7%BD%AE)下的,因为不属于app的生命周期: ```js A({ config: { extendPageBefore: function (def, { fns }) { // ... } } }); ```

extendPageBefore 是页面注册前执行,def是页面配置对象,可以往 def 挂载页面类方法(示例无关),你的用法是对的,只不过升级后 extendPageBefore 本来与 config同一层级,挪到了config里面

没在页面的`onUnload`生命周期上 clearTimeout 吧?