Aby
05/29/2023, 2:21 AMBrandon Reid
05/30/2023, 11:04 AMAby
05/30/2023, 11:12 PMRyan Peden
05/31/2023, 1:48 AMmount
method.
I'm doing partly from memory and partly from old apps where I've experimented with doing things like this,so I can't guarantee 100% accuracy, but here's how it might look. First, a tiny Vue app:
// myVueApp.js
import { createApp, ref } from "vue";
export function mountVueApp(el, props) {
const message = ref("Hello from Vue!");
// in your app, you'd want to import and use the Prefect UI components you're interested in.
const app = createApp({
setup() {
return { message };
},
template: `<div>{{ message }}</div>`,
});
app.mount(el);
}
Then, the Angular component you want to render the Vue app inside:
// my-angular-component.component.ts
import { Component, ElementRef, AfterViewInit, OnDestroy } from '@angular/core';
import { mountVueApp } from './myVueApp';
@Component({
selector: 'app-my-angular-component',
template: `<div #vueAppContainer></div>`,
})
export class MyAngularComponentComponent implements AfterViewInit, OnDestroy {
private vueApp: any;
constructor(private el: ElementRef) {}
ngAfterViewInit() {
const containerEl = this.el.nativeElement.querySelector('#vueAppContainer');
this.vueApp = mountVueApp(containerEl, {});
}
ngOnDestroy() {
// If your Vue app has any cleanup to do, do it here.
if (this.vueApp && typeof this.vueApp.unmount === 'function') {
this.vueApp.unmount();
}
}
}
I'd say it's more tedious than difficult, but you can make it work if you really, really want to use Vue components inside your Angular app. You'd need to choose a way to share state between your Angular and Vue apps. MobX might work well since it had both Angular and Vue bindings.Ryan Peden
05/31/2023, 1:53 AMRyan Peden
05/31/2023, 2:10 AM