Skip to content

Keep-Alive Doesn’t Work with Transition-Group #5892

@pingshunhuangalex

Description

@pingshunhuangalex

Version

2.3.4

Reproduction link

https://jsfiddle.net/kxemxsjy/1/

Steps to reproduce

The JsFiddle was created by a gentleman on Vue help forum, it's not a complete replicate of the problem, but it's a good starting point for my testing.

  1. Put something random to be cached by keep-alive in the card component
  2. Wrap keep-alive around card components directly (components won't rendered at all)
  3. Wrap keep-alive around card components directly and key the keep-alive (components won't rendered at all)
  4. Wrap keep-alive around transition-group (components rendered, but nothing gets cached)
  5. Specify name using include doesn't help either

What is expected?

Rating status (in rating component) should be kept for all cards correspondingly

What is actually happening?

Nothing's kept or the card components just not rendered at all due to Vue needs all items to be keyed (Which doesn't quite make sense for keep-alive...)

I went ahead and keyed the keep-alive anyway, but still no luck


I've been stuck on this issue for long enough, I think it's probably time to reach out for some help...

I have a search interface which displays results as card (using v-for), it will be switched to a different view card-reveal when user click on it.

There is a component inside each card called UserRating from which I want the rating info to be kept when users switch to card-reveal. I thought it was an obvious keep-alive case where the documentation seems to be quite straight forward. However, no matter where I wrap the keep alive (with target name), it just doesn't work... Some help would be appreciated. Thanks.

##Partial DOM structure for card and card-reveal

<div class="results-area">
More code here...

  <keep-alive include="UserRating">
    <transition-group name="card" tag="div">
      <Card v-if="expansionReady"
          v-for="result in apiResults"
          :result="result"
          :key="result.id" />
    </transition-group>
  </keep-alive>

More code here...

  <transition name="slideIn" tag="div">
    <CardReveal v-if="expansionMode" :result="currentApiResult" />
  </transition>
</div>

##Here is what UserRating component look like:

<template>
  <div class="user-rating">
    <i class="material-icons results-rate-up"
        :class="{toggled: rateStatus > 0}"
        @click.stop="userRate('up')">thumb_up</i>
    <i class="material-icons results-rate-down"
        :class="{toggled: rateStatus < 0}"
        @click.stop="userRate('down')">thumb_down</i>
    <span class="accuracy-score tooltipped"
        data-position="top"
        data-delay="50"
        data-tooltip="Accuracy Score"
        v-text="accuracyScore"
        v-show="accuracyScore !== 0">
    </span>
  </div>
</template>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions