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

重构计划:解决 MPVue 中存在的页面实例缓存问题 #2

Open
SuneBear opened this issue Oct 17, 2018 · 8 comments
Open
Labels

Comments

@SuneBear
Copy link

SuneBear commented Oct 17, 2018

目前 MPVue 在页面关闭后不会删除实例,从而会引发四个问题:

  1. 再次进入页面时,页面还保留上一次的旧数据,预期是清空数据
  2. 关闭页面时 Watcher 没有被取消订阅,再次进入页面会出现重复订阅的情况
  3. 因为复用了页面实例,部分生命周期函数会不执行,导致页面数据不完整
  4. 当页面异常中断后,会产生未捕获的错误,导致整个页面 Crash,再此进入也无法恢复

在实践了「抽奖」与「改图」小程序后,发现绝大多数问题都是由页面缓存引起的,如果每次进入是新的实例将会稳定很多

参见

@MooYoo
Copy link

MooYoo commented Oct 19, 2018

期待,急需解决这个问题,有预计的大概发布时间吗?

@zxzhgk
Copy link

zxzhgk commented Oct 29, 2018

遇到同样的问题,同一个组件第二次进入后,组件里面的watch ,computed 都不执行了,这完全不符合正常逻辑

@czy66545360
Copy link

还有slot也有问题,父级页面加载一个组件,在父级页面定义一个msg=1 ,放到slot里面初始化后msg会显示到slot标签内,但是后续如果修改msg的值,slot内的msg将没有反应。

@hucq
Copy link

hucq commented Nov 20, 2018

@SuneBear 上述问题我想了解更详细的 case 情况,方便加我微信么 chris_hcq,我正在处理这几个问题,你有好的实现,提供思路或者pr我们也都可以。

@SuneBear
Copy link
Author

@hucq Commit: f79f0f7e 是临时解决方案,最理想的方式是从 Compiler 层面解决,在页面 unload 阶段注销实例释放内存

@luojinghui
Copy link

luojinghui commented Jan 11, 2019

我也遇到了这个问题,在页面异常退出后,在进入子页面,data里面的值还是上一次的值,并不是初始默认的值。造成了很大的异常bug。很烦。

@jsydliuqing
Copy link

我这面也有这个问题,最终得到的解决方法如下::

  1. 再次进入页面时,页面还保留上一次的旧数据,预期是清空数据
  2. 关闭页面时 Watcher 没有被取消订阅,再次进入页面会出现重复订阅的情况
  3. 因为复用了页面实例,部分生命周期函数会不执行,导致页面数据不完整
  4. 当页面异常中断后,会产生未捕获的错误,导致整个页面 Crash,再此进入也无法恢复

1 和 2 可以用下面的方法解决:
在 src/main.js 中,添加如下代码:
Vue.mixin({ onUnload: function() { // Fixbug: 再次进入页面时,页面还保留上一次的旧数据(预期是清空数据) if (this.$options.data) { Object.assign(this.$data, this.$options.data()); } // Fixbug-Watcher: 关闭页面时 Watcher 没有被取消订阅,再次进入页面会出现重复订阅的情况 let watcherId = -1; if (this._watcher) { watcherId = this._watcher.id; this._watcher.teardown(); } let i = this._watchers.length; while (i--) { if (this._watchers[i].id === watcherId) { this._watchers[i].teardown(); } } } });

3 和 4 没有实际遇到,😶囧

@iampcfox
Copy link

我从去年关注到今年,都快一年了。
现在公司也倒闭了,项目也黄了。
唯独这个bug,这么久都没有官方解决方案…

现在没有做小程序了…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants