Skip to content

Instantly share code, notes, and snippets.

@sam-ngu
Created June 3, 2021 10:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sam-ngu/b383bcf72339889b9f6c9cc6d2dc1d14 to your computer and use it in GitHub Desktop.
Save sam-ngu/b383bcf72339889b9f6c9cc6d2dc1d14 to your computer and use it in GitHub Desktop.
Sample code to create a Vue 3 web component.
import { createApp, h } from 'vue'; // import components from Vue 3
import App from './App.vue';
// importing vue 3 web component wrapper
// https://www.npmjs.com/package/vue3-webcomponent-wrapper
import wrapper from "vue3-webcomponent-wrapper";
// This line will mount our component to the dom. This is only used in local development.
// but it is not necessary for the webcomponent wrapper to work.
// You can comment this out
createApp(App).mount('#app');
const CustomElement = wrapper(App, createApp, h)
// registering our component as 'my-custom-element'
// once build, we can simply load our component in the dom.
window.customElements.define('my-custom-element', CustomElement);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment