Skip to content

Cant get dom automatically when put the ref of directive in v-else branch #3030

@liaoliao666

Description

@liaoliao666

Version

3.0.5

Reproduction link

https://codesandbox.io/s/suspicious-wright-n3pi5?file=/src/App.vue

Steps to reproduce

<template>
  <a v-if="isShow" />
  <button v-else ref="el">el</button>
</template>

<script>
import { ref, watchEffect } from "vue";
export default {
  name: "App",
  setup() {
    const el = ref();
    const isShow = ref(true);

    setTimeout(() => {
      isShow.value = false;
    }, 3000);

    watchEffect(() => {
      console.log("change", el.value); // `undifined`
    });

    return {
      el,
      isShow,
    };
  },
};
</script>

What is expected?

should be get button

What is actually happening?

get undifined and just called once

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