[Vue] Dynamic component :is

We have a RadioGroupcomponent, when the prop verticalis true, we want all the Radiowrap with div, otherwise wrap with span.

<template>
  <component
    v-for="option in options"
    :key="option.value"
    :is="vertical ? 'div' : 'span'"
    :class="{
      horizontal: !vertical
    }"
  >
    <BaseRadio
      :label="option.label"
      :value="option.value"
      :modelValue="modelValue"
      :name="name"
      @update:modelValue="$emit('update:modelValue', $event)"
    />
  </component>
</template>

Parent component:

      <h3>Are pets allowed?</h3>
      <div>
        <BaseRadioGroup
          v-model="event.pets"
          name="pets"
          :options="petOptions"
          vertical
        />
      </div>

 

posted @   Zhentiw  阅读(6)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
历史上的今天:
2022-12-04 [Typescript] 126. Hard - Two Sum
2021-12-04 [AWS] Creating a Private Hosted Zone and Associating It with Multiple VPCs
2020-12-04 [Java Spring] Spring Expression Language
2020-12-04 [Java Spring] @Profile
2020-12-04 [Java Spring] @Value & override properties by environment variables
2019-12-04 [Schematics] 2. EJS
2019-12-04 [Algorithm] Bitwise Operators
点击右上角即可分享
微信分享提示