Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

83
Views
Dynamic Slots with VueJS

I've got a component that is meant to render one component or the other depending on the presence of a feature flag. This is done via the :is property on the dynamic component component.

<template>
  <component
    :is="hasFF ? 'ButtonTwo' : 'ButtonOne'"
    v-bind="$attrs"
  />
</template>

<script>
import ButtonOne from './ButtonOne.vue'
import ButtonTwo from './ButtonTwo.vue'
import { BUTTON_TWO } from '@/constants/feature_flags'
import { mapGetters } from 'vuex'
export default {
  name: 'ButtonWrapper',
  components: {
    ButtonOne,
    ButtonTwo,
  },
  computed: {
    ...mapGetters(['hasFeatureFlag']),
    hasBittsTwo () {
      return this.hasFeatureFlag(BUTTON_TWO)
    },
  },
}
</script>

However, both ButtonOne and ButtonTwo in this example contain slots. For instance here is a contrived usage of the first button:

<ButtonOne>
   <slot name="icon">
   <button>Click Me</button>
   <div>Some more text</div>
</ButtonOne>

How can I write a wrapper component that checks for the presence of a feature flag and then renders it's children, including by passing down all of their props and appropriately rendering their slots? Could this be more easily achieved using a render function, and if so, how?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!