0

I'm looking for a suggestion regarding a cleaner approach to generate a component data as html string and to pass it raw through the props of the component.

component-a.js
import componentB from './component-b'  



computed: {
  tooltipHTML() {
    render "<componentB :name='user1'/>
  }
}

I would prefer something similar to the above idea.

1 Answer 1

2

Generating HTML in a computed property and passing it as props to another component to be rendered in that component will not work.

What you are looking for is Slots

Since the complete code is not provided I guess you wanted to render <componentB :name='user1'/> inside another component( a tooltip component)

You would be doing it as follows using slots:

<tooltip-comp>
    <componentB :name='user1'/>
</tooltip-comp>

In your tooltip component

//tooltip component

<template>
    <div class="my-tooltip">
        <p>my tooltip</p>
        <slot></slot>
    </div>
</template>
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.