Skip to content

feat(keep-alive): includes/excludes keep-alive based on key and name (fix #8028) #10245

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

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

RobbinBaauw
Copy link

The keep-alive component will now also use the key of the component when checking the includes or excludes properties.

On this way you can cache specific instances of a component instead of caching all instances of that component.

fix #8028

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change?

  • Yes
  • No

The PR fulfills these requirements:

The keep-alive component will now also use the key of the component when checking the includes or excludes properties.

fix vuejs#8028
@qtttttttttting
Copy link

qtttttttttting commented Jul 17, 2019

How to use it?Any example?I try it, but faild.

@RobbinBaauw
Copy link
Author

I've made a JSFiddle: https://jsfiddle.net/87t53pwd/18/.

A small explanation: In the keep-alive block we have 3 usages of the same component with each a different state. We only want to keep the state cached of the first 2, and not the last.

The current version of keep-alive doesn't allow for this (because it only uses the name of the component, not the key). Now, it also looks at the key (so if either the name or the key matches something in the includes array, it caches it).

You can replace the newly built version of Vue by the old one and see the difference (it works vs it doesn't)

@qtttttttttting
Copy link

qtttttttttting commented Jul 22, 2019

Thank you for your answer.
But I install vue via git://github.com/vuejs/vue.git#dev, but it seems not to work .

@RobbinBaauw
Copy link
Author

Yes, because this pull request has not been merged yet. If you try dev on my fork it should work

@qtttttttttting
Copy link

qtttttttttting commented Jul 22, 2019

I have urgent need for this function in my project. When will it be merged? Or I can use RobbinBaauw:dev branch?
Thank you .

@RobbinBaauw
Copy link
Author

I can't merge it, the vue authors need to do that. You can use that branch if you want, you'll see here when / if it will be merged

@qtttttttttting
Copy link

OK. Thank you so much.

@qtttttttttting
Copy link

I try to install git://github.com/RobbinBaauw/vue.git#dev, but it seems not work with vue-router

@RobbinBaauw
Copy link
Author

Can you make a fiddle? In the project I use it for it works, also with vue-router.

Also, how did you use it? You should build vue manually as well as its dist files are not yet updated.

@qtttttttttting
Copy link

Sorry, it is my mistake.It works now.Thank you .

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

Successfully merging this pull request may close these issues.

keep-alive: include/exclude components by component key attribute
2 participants