Optional parent element in Vue.js

前端 未结 3 1285
走了就别回头了
走了就别回头了 2020-12-17 21:26

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:



        
3条回答
  •  盖世英雄少女心
    2020-12-17 22:16

    Not sure why my previous answer was deleted. Turns out you can't just C&P answers across multiple Qs. I've gone ahead and flagged the other Qs as dups of this one (I'm trying here... come on moderators...)


    I've run into this exact issue several times myself and decided to go ahead and create a module with the solution I've been using locally, which can find on NPM:

    vue-wrapped-component

    This module provides a functional Vue component that allows any component or element to be conditionally wrapped using another component or element.

    The previous answers semi-work for very basic of circumstances. This module provides a more robust solution that works in almost any situation, especially complex ones where there's a risk of duplicating lots of code just because you need a simple conditional wrapper.

提交回复
热议问题