I have a component that renders text based on user membership status and I want to change the interpolated text based on that property value. Is there a more efficient way to display different text based on props other than a bunch of div/p tags using v-if
or v-show
?
Constantly having a bunch of stacked divs with just tons of text.
Any suggestions would be greatly appreciated!
cheers!
<script lang="ts" setup> import { PropType } from 'vue' const props = defineProps({ kind: { type: String as PropType<'subscribed' | 'unsubscribed'>, default: 'subscribed', }, planId: { type: String as PropType<'standard' | 'silver' | 'gold' | 'platinum' | 'diamond' | 'no plan'>, default: 'standard', }, }) </script> <template> <div class="c-promotion-plan-card" data-cy="component-promotion-plan-card"> <div class="flex items-baseline mb-sm"> <div v-if="planId === 'standard'" class="text-h6 text-dark">Standard Gang</div> <div v-if="planId === 'silver'" class="text-h6 text-dark">Silver Foxes</div> <div v-if="planId === 'gold'" class="text-h6 text-dark">Golden Girls</div> <div v-if="planId === 'platinum'" class="text-h6 text-dark">Platinum Boys</div> <div v-if="planId === 'diamond'" class="text-h6 text-dark">Diamond Dudes</div> <div v-if="planId === 'no plan'" class="text-h6 text-dark"> No Plan Posse </div> </div> </div> </template>
Yes, there is a better way. You can define a computed property like Vue2 Syntax
Vue3 Syntax
Then call the interpolation calculation within the template, for example
Maybe something like the following code snippet (map your plan and use computed properties):