Vue dynamic component

 from Red Blob Games
1 Jun 2025

Vue components are just objects. That means we can construct a new component at run time. This is a quick test page.

The new component here has two props and a template, which you can edit above.

            return { // this is a new component made at run time
                props: ['a', 'b'],
                template: templateText.value,
            };

I find it easier to build run time components using the options api, but the vue community seems to be moving towards the composition api.

To handle a template, you need the “runtime” build of Vue[1], which can compile templates at run time. I’m doing that here.

To handle SFC files (*.vue), you need to use the SFC compiler[2]. I’m not doing that here.

Source: vue-dynamic-component.js

Email me , or comment here: