aircox-radiocampus/assets/src/vueLoader.js
Chris Tactic 55123c386d #132 | #121: backoffice / dev-1.0-121 (#131)
cfr #121

Co-authored-by: Christophe Siraut <d@tobald.eu.org>
Co-authored-by: bkfox <thomas bkfox net>
Co-authored-by: Thomas Kairos <thomas@bkfox.net>
Reviewed-on: rc/aircox#131
Co-authored-by: Chris Tactic <ctactic@noreply.git.radiocampus.be>
Co-committed-by: Chris Tactic <ctactic@noreply.git.radiocampus.be>
2024-04-28 22:02:09 +02:00

48 lines
1.1 KiB
JavaScript

import {createApp} from 'vue'
import PageLoad from './pageLoad'
/**
* Handles loading Vue js app on page load.
*/
export default class VueLoader {
constructor({el=null, props={}, ...appConfig}={}, loaderOptions={}) {
this.appConfig = appConfig
this.appConfig.el = el
this.props = props
this.pageLoad = new PageLoad(el, loaderOptions)
this.pageLoad.onPreMount = event => this.onPreMount(event)
this.pageLoad.onMount = event => this.onMount(event)
}
enable(hotReload=true) {
hotReload && this.pageLoad.enable(document.body)
this.mount()
}
mount() {
if(this.app)
this.unmount()
const app = createApp(this.appConfig, this.props)
app.config.globalProperties.window = window
this.vm = app.mount(this.pageLoad.el)
this.app = app
}
unmount() {
if(!this.app)
return
try { this.app.unmount() }
catch(_) { null }
this.app = null
this.vm = null
this.pageLoad.reset()
}
onPreMount() { this.unmount() }
onMount() { this.mount() }
}