1

suppose we have a component like this.

<template>
 <div class=" ">
   <div class="flex-grow">{{title}}</div>
   <div class=" p-5">
     <!-- want to show here -->
   </div>
 </div>

 <script>
   export default {
     props: ['title'],
     mounted() {
       console.log('Component mounted.')
     }
   }
 </script>

i try this

<comp :title="'here'">
 <h1> this is </h1> 
</comp>

i want to show html b.w vue component tag, like we do in react. how we can achieve this

2
  • I think you're looking for <slot></slot> reference Commented Oct 26, 2018 at 22:26
  • what do you mean? Commented Oct 26, 2018 at 22:42

1 Answer 1

1

If I understand the question, you're looking to create a component that can accept child elements. In order to do this, use <slot></slot> in your template where you'd like child elements to be inserted. Child elements can be other components or HTML.

See the reference for more thorough details.

In your example:

<template>
 <div class=" ">
   <div class="flex-grow">{{title}}</div>
   <div class=" p-5">
     <slot></slot>
   </div>
 </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.