How to declare a list of slots with dynamic names and dynamic components in a VueJS template?

前端 未结 1 1997
时光取名叫无心
时光取名叫无心 2021-02-07 17:46

Suppose I have a component with data:

data: function () {
  return {
    slots: [
      { Id: 1, slotName: \'apple\', comp         


        
相关标签:
1条回答
  • 2021-02-07 18:36

    You can use v-for into a template component

    You just need to specify the key on the component.

    <child-component>
      <template v-for="slot in slots" v-slot:[slot.slotName]="slotProps">
        <component :key="slot.Id" :someProp="slotProps"></component>
      </template>
    </child-component>
    
    0 讨论(0)
提交回复
热议问题