Subscribe on changes!

computed里面调用vant组件,会触发vue的更新机制错误问题

avatar
Oct 8th 2021

Version

3.2.11

Reproduction link

codesandbox.io

Steps to reproduce

点击页面的按钮即可触发

What is expected?

正常弹出toast

What is actually happening?

控制台以及页面报错


分析似乎是computed触发相关依赖更新,但是toast组件部分el是空的,导致报错问题

avatar
Oct 8th 2021

Open the issue in vant repository first.

avatar
Oct 8th 2021

Open the issue in vant repository first.

Yes, I have been opened.https://github.com/youzan/vant/issues/9487

avatar
Oct 8th 2021

Then please read and follow https://new-issue.vuejs.org/?repo=vuejs/vue-next#why-repro when reporting a bug. Most bugs should be reproducible with the SFC Playground.

avatar
Oct 8th 2021

Then please read and follow https://new-issue.vuejs.org/?repo=vuejs/vue-next#why-repro when reporting a bug. Most bugs should be reproducible with the SFC Playground.

Ok, let me check check the vant's sourcecode then reply you.

avatar
Oct 8th 2021

Sure, make sure it's boiled down. Obviously don't copy paste the code from vant's Toast in the SFC...

avatar
Oct 8th 2021

@wensc1996 Try like this:

    const name = computed(() => {
      if (x.value == 0) {
        return "张三";
      } else {
        nextTick(() => {
          Toast("你好");
        });
        return "李四";
      }
    });
avatar
Oct 8th 2021

@wensc1996 Try like this:

    const name = computed(() => {
      if (x.value == 0) {
        return "张三";
      } else {
        nextTick(() => {
          Toast("你好");
        });
        return "李四";
      }
    });

thanks, maybe the vue-createVnode conficts with computed update

avatar
Oct 13th 2021

@posva :sweat_smile: I simplified test case, But not sure if it's a bug. sfc.vuejs.org

avatar
Oct 13th 2021

Why are you applying side effects in computed instead of watch/watchEffect?

avatar
Oct 13th 2021

Calling the createApp inside of a computed() seems really weird. It should run outside