DEV Community

Cover image for From 0 to 100 within seconds in dynamic rendering of Vue Components
Marcos Henrique
Marcos Henrique

Posted on

3 3

From 0 to 100 within seconds in dynamic rendering of Vue Components

Straight to the point like fast and furious


I've been working on a project where there was a need to render Vue components programmatically, which is the hard way 😅, even passing props.

So I will quickly show you how to do this.

So let's suppose we have a component called Card, which gets its title via props

import Card from 'Card.vue'
import Vue from 'vue'
let ComponentClass = Vue.extend(Card)
let instance = new ComponentClass({
    propsData: {
        title: 'My Title'
    }
})
instance.$mount() 
this.$refs.container.appendChild(instance.$el)
Enter fullscreen mode Exit fullscreen mode

First of all, $refs is the most recommended way to get a DOM element referenced in Vue.

You need to specify an attribute on the DOM element you want to reference (<div ref="container"> </div> in our case), and then that element is available in the key defined in the $refs property of the component.

Finally, to get the native DOM element reference from an instance of the Vue component, you can use the $el property.

From 0 to 100 within seconds in dynamic rendering like a Dodge Charger, anything I am available in the comments, for today that's my consecrated 🍻

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

AWS GenAI LIVE!

GenAI LIVE! is a dynamic live-streamed show exploring how AWS and our partners are helping organizations unlock real value with generative AI.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️