aboutsummaryrefslogtreecommitdiff
path: root/resources/assets/javascripts/chunks/vue.js
blob: 3cf27d06d6ce749fb7a96622a9caddf3f64a119f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import Vue from 'vue';
import Vuex from 'vuex';
import Router from "vue-router";
import eventBus from '../lib/event-bus.js';
import GetTextPlugin from 'vue-gettext';
import { getLocale, getVueConfig } from '../lib/gettext.js';
import PortalVue from 'portal-vue';
import BaseComponents from '../../../vue/base-components.js';
import BaseDirectives from "../../../vue/base-directives.js";

Vue.mixin({
    methods: {
        globalEmit(...args) {
            eventBus.emit(...args);
        },
        globalOn(...args) {
            eventBus.on(...args);
        },
    },
});

Vue.use(GetTextPlugin, getVueConfig());
eventBus.on('studip:set-locale', (locale) => {
    Vue.config.language = locale;
})

registerGlobalComponents();
registerGlobalDirectives();

Vue.use(Vuex);
const store = new Vuex.Store({});

Vue.use(Router);

Vue.use(PortalVue);

function createApp(options, ...args) {
    return new Vue({ store, ...options }, ...args);
}

function registerGlobalComponents() {
    for (const [name, component] of Object.entries(BaseComponents)) {
        Vue.component(name, component);
    }
}

function registerGlobalDirectives() {
    for (const [name, directive] of Object.entries(BaseDirectives)) {
        Vue.directive(name, directive);
    }
}

export { Vue, createApp, eventBus, store };