Skip to content
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

v-if does not work on the slot #3

Open
xandao-dev opened this issue Dec 6, 2023 · 2 comments
Open

v-if does not work on the slot #3

xandao-dev opened this issue Dec 6, 2023 · 2 comments

Comments

@xandao-dev
Copy link

The example provided in the readme does not work because modalOpen starts false, in the Teleport mounted the nodes are settled, but it doesn't watch for node changes.

<template>
  <div>
      <button @click="modalOpen = true">
          Open full-screen modal! (With teleport!)
      </button>
    
      <Teleport to="body">
        <div v-if="modalOpen" class="modal">
          <div>
            I'm a teleported modal! 
            (My parent is "body")
            <button @click="modalOpen = false">
              Close
            </button>
          </div>
        </div>
      </Teleport>
  </div>
</template>

Workaround: Make sure to have an initial node.

<template>
  <div>
      <button @click="modalOpen = true">
          Open full-screen modal! (With teleport!)
      </button>
    
      <Teleport to="body">
        <div v-show="modalOpen" class="modal">
          <div v-if="modalOpen">
            I'm a teleported modal! 
            (My parent is "body")
            <button @click="modalOpen = false">
              Close
            </button>
          </div>
        </div>
      </Teleport>
  </div>
</template>

Long-term solution:
Watch for node changes in the Teleport component.

@Mechazawa
Copy link
Owner

Didn't consider that when I built it. I'll have a look at it

@jackiotyu
Copy link
Contributor

jackiotyu commented May 9, 2024

#2
#7

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

No branches or pull requests

3 participants