OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How to render component instance with h() function in Vuejs?

  • Thread starter Thread starter gespinha
  • Start date Start date
G

gespinha

Guest
I have a Vuejs component that looks like this:

Code:
<template>
  <button @click="generateItem()">Add item</button>
  <div class="container"></div>
</template>

<script setup>
  import { h } from 'vue'
  import MyItem from '@/components/MyItem.vue'

  function generateItem(){
    return h(MyItem)
  }
</script>

I'm trying to use an h() function to render an instance of MyItem inside div.container when running generateItem(). But after reading the official Vuejs docs on the h() function I don't get how to make this happen. Thoughts on how to get this done?

<p>I have a Vuejs component that looks like this:</p>
<pre><code><template>
<button @click="generateItem()">Add item</button>
<div class="container"></div>
</template>

<script setup>
import { h } from 'vue'
import MyItem from '@/components/MyItem.vue'

function generateItem(){
return h(MyItem)
}
</script>
</code></pre>
<p>I'm trying to use an <code>h()</code> function to render an instance of <code>MyItem</code> inside <code>div.container</code> when running <code>generateItem()</code>. But after reading the official Vuejs docs on the <code>h()</code> function I don't get how to make this happen. Thoughts on how to get this done?</p>
 

Latest posts

M
Replies
0
Views
1
Mohit Pant
M
Top