I want to render this " /> I want to render this " /> I want to render this "/>

How to render a dynamic slot component in Storybook (Nuxt3)

387 views Asked by At

I have a dynamic named slot that looks as below.

<div>
  <template #middle>
    <slot :name="`middle-${index}`" />
  </template>
</div>

I want to render this in Storybook but not sure how to set the template and render it. The code below wouldn't work. How can I achieve this?

template: `
  <StoryComponent v-bind="args">
    <template 
      v-for="(content, index) in args.middle" 
      :key="index" 
      :slot="'middle-' + index" //WANT TO SET THE NAME PROPERLY
    >
      {{content}}
    </template>
  </StoryComponent>
`,
2

There are 2 answers

0
user16589580 On

I solved it by changing it to below.

<template 
      v-for="(content, index) in args.middle" 
      :key="index" 
      #[\`middle-\${index}\`]
    >
0
hashem shafai On

You can use index as props

 <StoryComponent v-bind="args">
<template 
  v-for="(content, index) in args.middle" 
  :key="index" 
  :slot="'middle-' + index"
  :index="index"
>
  {{content}}
</template>