N
N
nonamer_city2022-02-04 09:51:07
Vue.js
nonamer_city, 2022-02-04 09:51:07

Is it possible to pass parameters in a loop?

Hello.
I want to ask if it is possible to output the parameters that I pass to the props in the loop.
For example:

[
{
  componentName:Button,
  title: Кнопка,
  label: : Желтая кнопка
},
{
  componentName:Select,
  options:[1,2] ,
  type:select
},
]

There is such an array. I display it in v-for and and component is=componentName
But how to pass parameters so that it looks something like this
Component is=component name :options=options :label=label

All components are different.
Making one object out of this is not an option. Props structure is typed

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2022-02-04
@0xD34F Vue.js

Move all parameters to a separate object:

[
  {
    name: 'componentName1',
    props: {
      propName1: ...,
      propName2: ...,
    },
  },
  {
    name: 'componentName2',
    props: {
      propName69: ...,
      propName187: ...,
      propName666: ...,
    },
  },
  ...
]

<component
  v-for="n in componentsData"
  v-bind="n.props"
  :is="n.name"
/>

E
Evgeniy S, 2022-02-05
@evgensenin

In the usual way, as you are used to - do not do this.
But you can do it through the render function
. Submit the necessary props depending on the type of component.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question