diff options
| author | Jan-Hendrik Willms <tleilax+github@gmail.com> | 2021-07-22 16:07:19 +0200 |
|---|---|---|
| committer | Jan-Hendrik Willms <tleilax+github@gmail.com> | 2021-07-22 16:19:12 +0200 |
| commit | a3da1483a9e689846179159355badfec8073dbec (patch) | |
| tree | 770dcca6bdf5f6f2a11b0e7fcbbeda6919a3fc52 /resources/assets/javascripts/bootstrap/vue.js | |
current code from svn, revision 62608
Diffstat (limited to 'resources/assets/javascripts/bootstrap/vue.js')
| -rw-r--r-- | resources/assets/javascripts/bootstrap/vue.js | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/resources/assets/javascripts/bootstrap/vue.js b/resources/assets/javascripts/bootstrap/vue.js new file mode 100644 index 0000000..550f097 --- /dev/null +++ b/resources/assets/javascripts/bootstrap/vue.js @@ -0,0 +1,59 @@ +/** + * The following block of code is used to automatically register your + * Vue components. It will recursively scan this directory for the Vue + * components and automatically register them with their "basename". + * + * Eg. ./components/ExampleComponent.vue -> <example-component></example-component> + */ +STUDIP.ready(() => { + $('[data-vue-app]').each(function () { + if ($(this).is('[data-vue-app-created]')) { + return; + } + + const config = Object.assign({}, { + id: false, + components: [], + store: false + }, $(this).data().vueApp); + + let data = {}; + if (config.id && window.STUDIP.AppData && window.STUDIP.AppData.hasOwnProperty(config.id)) { + data = window.STUDIP.AppData[config.id]; + } + + let components = {}; + config.components.forEach(component => { + components[component] = () => import(`../../../vue/components/${component}.vue`); + }); + + STUDIP.Vue.load().then(async ({createApp, store}) => { + let vm; + if (config.store) { + const storeConfig = await import(`../../../vue/store/${config.store}.js`); + console.log('store', storeConfig.default); + + store.registerModule(config.id, storeConfig.default, {root: true}); + + Object.keys(data).forEach(command => { + store.commit(`${config.id}/${command}`, data[command]); + }); + vm = createApp({ + components, + ...mapGetters() + }); + } else { + vm = createApp({data, components}); + } + // import myCoursesStore from '../stores/MyCoursesStore.js'; + // + // myCoursesStore.namespaced = true; + // + // store.registerModule('my-courses', myCoursesStore); + + vm.$mount(this); + }); + + $(this).attr('data-vue-app-created', ''); + }); +}); |
