Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

200
Views
Passing HTML or Components to the Vue Plugin

I have created the basic Vue component which is as follow.

<template>
  <div class="example">
    /* here render the component or HTML passed by pluing */
  </div>
</template>

<script lang="ts">
import Vue from 'vue';
export default Vue.extend({
  name: 'Example',
});
</script>

Now I need to create a plugin that will render any HTML or Component passed to the Example.I know the basic syntax of plugins and how to use them in the Vue but don't know how to do this task since I am a newbie to Vue.

export default {
    install(vue, opts){ 
      /* how to take the component or HTML and pass to `Example` Component */
    }
}

I need to implement these in vue2.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use a slot to render an arbitrary HTML inside any of your components.

Your Example Component:

<template>
  <div class="example">
    <slot />
  </div>
</template>

<script lang="ts">
import Vue from 'vue';
export default Vue.extend({
  name: 'Example',
});
</script>

Then use it like this:

<template>
  <example>
    <div>Render me inside the slot</div>
  </example>
</template>

And it will result in the following rendered HTML:

<div class="example">
  <div>Render me inside the slot</div>
</div>

Then in you plugin you can use your Example component and pass any html you want to it

Update: this how your plugin might look like. Just create a global component inside of it

import Vue from 'vue'

const ExamplePlugin = {
  install(Vue){
    Vue.component('Example', {
      name: 'Example',
      template: '<div class="example"><slot /></div>'
    })
  }
}

Then you can Vue.use(ExamplePlugin) and Example component will be available globally in your application

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!