question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add "keep-children" argument to v-if

See original GitHub issue

What problem does this feature solve?

Imagine you have this component for wrapping an input:

<template>
  <div class="container">
    <input />
  </div>
</template>

Like in this case I have several others where I would like to make only the container enclosing tag conditionally visible, but keeping the input, so it would be:

<template>
    <input />
</template>

… depending on certain condition.

I know it’s possible to achieve this using the render function, but it’s too hard for me to maintain those (big in my case) components without really viewing the template as HTML itself.

What does the proposed API look like?

So, my suggestion is to add an argument to the v-if directive like “keep-children”. This way I could do something like:

<template>
  <div v-if:keep-children="showContainer" class="container">
    <input />
  </div>
</template>

<script>
export default {
  props: ['showContainer']
}
</script>

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
sqalcommented, Jun 18, 2018

You can achieve it by creating really simple functional component https://jsfiddle.net/hpeocn97/

1reaction
Justineocommented, Jun 18, 2018

Yes currently we can only use render function to implement a conditional wrapper with a lot of content.

Instead of introducing a modifier for v-if, maybe I would rather use something like:

<template>
  <div v-transparent="!showContainer" class="container">
    <input />
  </div>
</template>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Video of Joe Biden Wandering Around Toy Store Sparks Debate
The clip of Joe Biden appearing to walk aimlessly around carrying toys during an event has been viewed more than 880000 times.
Read more >
Video: COUNTIFS and SUMIFS - Microsoft Support
Training: COUNTIFS applies criteria to cells across multiple ranges and counts the number of times all criteria are met. SUMIFS adds the cells...
Read more >
VAST ad tag URL parameters - Google Ad Manager Help
A VAST ad tag URL is used by a player to retrieve video and audio ads. ... The child-directed parameter accepts a constant...
Read more >
O'Shea Jackson Jr., Lily Allen & More Defend Children of ...
O'Shea Jackson Jr., Lily Allen - Video - 2022 ... Jackson Jr., Lily Allen & More Defend Children of Celebrities Amid Viral Debate...
Read more >
Students fake an argument to surprise principal for her birthday
Gabrielle Flores, of California, went viral when she shared her family's Christmas plan on Tiktok, writing in a video that she told her ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found