0

I have multiple components that take same props. I want to use those components in template in such a way that I don't use multiple if-else statements in my template. I created an object in my data and paired my components with string keys. Is there a way to call those components in template with that object ? My data object looks something like this:

componentMap:{
  "testComponent1":TestComponent1,
  "testComponent2":TestComponent2,
},

For example, if I give "testComponent1" as key, then in template it should use TestComponent.

1 Answer 1

3

Use the component tag.

<component :is="componentMap['testComponent1']"></component>

See the Docs

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.