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

当component绑定key时,keep-alive的max存在问题 #10297

Closed
waldonUB opened this issue Jul 21, 2019 · 1 comment
Closed

当component绑定key时,keep-alive的max存在问题 #10297

waldonUB opened this issue Jul 21, 2019 · 1 comment

Comments

@waldonUB
Copy link

waldonUB commented Jul 21, 2019

Version

2.6.10

Reproduction link

https://codepen.io/waldonUB/pen/PMqXdr

Steps to reproduce

  1. 点击第二个tem1按钮,将key值切换到 b
  2. 点击temp2,将key值切换到 c

What is expected?

因为max设置为2,所以到第3个key值时,key值为a的temp1组件应该被销毁

What is actually happening?

到了第三个key值的时候没有key值为a的temp1组件没有被销毁,而是到了第四个key值的时候才被销毁


使用场景

  • 我需要对话框来缓存数据,但是很多对话框是相同的组件,以不同的编码来查询不同的数据
  • 以编码作为key值绑定在component上缓存组件,避免重新打开时再次查询
  • 加上max属性,防止内存溢出

绑定key时,max存在的问题

  • 当同一个组件有多个key绑定时,当key的数量 >= max的值,max将会缓存相同的key,不会触发生命周期中的destroyed函数

以往类似的issue

@posva
Copy link
Member

posva commented Jul 21, 2019

Please check #8028
Components are cached based on their name right now so temp1 with key a and temp1 with b will use the same cache spot and override each other

@posva posva closed this as completed Jul 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants