Created
June 3, 2021 10:51
-
-
Save sam-ngu/b383bcf72339889b9f6c9cc6d2dc1d14 to your computer and use it in GitHub Desktop.
Sample code to create a Vue 3 web component.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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