[Vuejs]-Is there a way to create a vue component and add it to the dom like you would an html element?

0👍

you can try to use v-if, but also you can try to create new app inside yours just by createApp(App).mount("#app");

0👍

I’m looking into this for a go-based site. A couple of possibilities:

  1. You can use Petit Vue, which is a small build of Vue 3 that is designed for this. I’d guess your component isn’t very large; if so, this might be a good option for you. You just load the Vue code up from a CDN, and you can put your component code right into your page’s Javascript. It’s pretty simple.

  2. If you want to do something larger, you want to build Vue (I’m using the newest version, which builds with the new Vite build system), and you need to somehow get the CSS and Javascript bundles it creates to get loaded into your pages. I can explain how to do this in more detail if you really want to try it — I don’t think there’s a good tutorial around to point you to.

  3. If you use one of the systems listed here, you can use your platform to do the magic you need to do for (2). I think that Ruby on Rails, WordPress, Drupal and a few other popular platforms have this.

Leave a comment