如何通过 props 将对象中的 render 渲染为组件

2022-10-30 18:36:53 +08:00
 jahnsli
  {
    type: 'radio',
    formItemProps: { label: useI18nt('test') },
    model: 'test',
    slots: [
      {
        name: 'default',
        render: () => [
          h(NRadioButton, { size: 'large', value: 1, label: '1' }),
          h(NRadioButton, { size: 'large', value: 2, label: '2' })
        ]
      }
    ]
  }

<component is='radio'>
  How would you render a slots from an object here by passing props
</component>
1076 次点击
所在节点    Vue.js
2 条回复
chenjiangui998
2022-10-31 11:16:31 +08:00
{
type: 'radio',
formItemProps: { label: useI18nt('test') },
model: 'test',
slots: [
{
name: 'default',
render: () => [
h(NRadioButton, { size: 'large', value: 1, label: '1' }),
h(NRadioButton, { size: 'large', value: 2, label: '2' })
]
}
]
}

<component is='radio'>
<component v-for="slot in slots" :is="slot.render" :key="slot.name"/>
</component>

试试这样, 不行就把 setup 去了, 用 render 函数
sjhhjx0122
2022-10-31 20:32:51 +08:00
vue 的 script lang 是可以为 tsx 的,这样你直接把变量当组件也是可以的

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/891209

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX