Skip to content

Commit

Permalink
use custom element
Browse files Browse the repository at this point in the history
  • Loading branch information
Armin Jazi committed May 7, 2024
1 parent 631437c commit bb9cb9a
Showing 1 changed file with 37 additions and 4 deletions.
41 changes: 37 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,38 @@
import { createApp } from 'vue'
import './style.css'
import App from './App.vue'
import "@openreply/pattern-library/styles";
import "@obi-dbs/customer-ui-components/styles";

createApp(App).mount('#app')
import { App as VueApp, createApp } from "vue";

import App from "./App.vue";
const elementName = "page-module-share-vue";
class PageModuleShareVue extends HTMLElement {
private app: VueApp | null = null;
private mountPoint: HTMLElement | null = null;

static get observedAttributes() {
return ["user-type"];
}

connectedCallback() {
this.mountPoint = document.querySelector(elementName);
this.setup();
}

setup() {
if (this.app) this.app.unmount();

if (this.mountPoint) {
this.app = createApp(App);
this.app.mount(this.mountPoint);
console.log("page-module-share-vue: Mounted");
} else {
console.log("page-module-share-vue: Mount point not found");
}
}
}

if (!window.customElements.get(elementName)) {
window.customElements.define(elementName, PageModuleShareVue);
} else {
console.warn(`${elementName}: Custom element already defined`);
}

0 comments on commit bb9cb9a

Please sign in to comment.