Is there any way to define the parent element as optional based on a condition but always show its children in Vue.js?
For example:
<a :href="link">Some text</a>
What I would like to achieve is the following DOM depending on link
<a href="somelink">Some text</a> <!-- when link is truthy -->
Some text <!-- when link is falsy -->
Potential solutions
Duplicate the children:
<a :href="link" v-if="link">Some text</a>
<template v-if="!link">Some text</template>
But that is not a good solution especially as there might be more content than just a simple text.
Write my own component that does the logic depending on some attribute. But this seems overkill and also has to be flexible enough for different kind of element types or attributes.
As I don't like either of these approaches, I wonder whether there is no simpler solution. Any ideas?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…