Skip to content

keep-alive组件的include中如果使用的是一个ref([]),并且延迟添加,会不起效,而且组件不能再次激活,绑定也会失效 #4984

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

Closed
lejianwen opened this issue Nov 23, 2021 · 7 comments

Comments

@lejianwen
Copy link

Version

3.2.22

Reproduction link

codesandbox.io

Steps to reproduce

点击chang按钮,到tab2 组件, 再点change回来,onActivated不会触发,并且tab1中两个input绑定的同一个ref也会断开。
使用computed也必须注意要返回Array才行。

What is expected?

按道理应该点击回来tab1的onActivated会触发,并且绑定不会断开

What is actually happening?

onActivated不会触发,并且tab1中两个input绑定的同一个ref也断开了


include暂时不支持使用ref么?

@ygj6
Copy link
Member

ygj6 commented Nov 23, 2021

Maybe you could consider changing keeps.value = ["tab2"]; to keeps.value = ["tab1"]; as workaround.

setup() {
    const cn = ref("tab1");

    // use  ref
    const keeps = ref([]);
    keeps.value = ["tab2"];     -------------> keeps.value = ["tab1"]; 
    setTimeout(() => {
      keeps.value.push("tab1"); // fail
      // keeps.value = ["tab1", "tab2"]; //ok
    }, 500);

@edison1105
Copy link
Member

edison1105 commented Nov 23, 2021

as a workround

:include="[...keeps]"

include and exclude should not pass reactive data.
see https://v3.vuejs.org/guide/reactivity-computed-watchers.html#watching-reactive-objects

the watch will not trigger if include is reactive. maybe we should improve this code:

    // prune cache on include/exclude prop change
    watch(
      () => [props.include, props.exclude],
      ([include, exclude]) => {
        include && pruneCache(name => matches(include, name))
        exclude && pruneCache(name => !matches(exclude, name))
      },
      // prune post-render after `current` has been updated
      { flush: 'post', deep: true }
    )

@LinusBorg
Copy link
Member

Seems to me like it would trigger, because of deep: true being set: Playground

@lejianwen
Copy link
Author

谢谢大家
只是感觉各种方式都有点绕,不太符合3.x的风格
@edison1105 的方式很简洁明了,我拿走了

@edison1105
Copy link
Member

@lejianwen 这应该是个 bug,还没来得及调查,后面会修复的。
this should be a bug, beacuse tab1.vue is unmounted.
image

@liulinboyi
Copy link
Member

liulinboyi commented May 12, 2022

This issue is fixed by commit.

@posva
Copy link
Member

posva commented Jul 19, 2022

This is indeed fixed

@posva posva closed this as completed Jul 19, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Sep 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants