main.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import Vue from 'vue';
  2. import Buefy from 'buefy';
  3. import humps from 'humps';
  4. import VueI18n from 'vue-i18n';
  5. import App from './App.vue';
  6. import router from './router';
  7. import store from './store';
  8. import * as api from './api';
  9. import { models } from './constants';
  10. import Utils from './utils';
  11. // Internationalisation.
  12. Vue.use(VueI18n);
  13. const i18n = new VueI18n();
  14. Vue.use(Buefy, {});
  15. Vue.config.productionTip = false;
  16. // Globals.
  17. const ut = new Utils(i18n);
  18. Vue.mixin({
  19. computed: {
  20. $utils: () => ut,
  21. $api: () => api,
  22. },
  23. methods: {
  24. $reloadServerConfig: () => {
  25. // Get the config.js <script> tag, remove it, and re-add it.
  26. let s = document.querySelector('#server-config');
  27. const url = s.getAttribute('src');
  28. s.remove();
  29. s = document.createElement('script');
  30. s.setAttribute('src', url);
  31. s.setAttribute('id', 'server-config');
  32. s.onload = () => {
  33. store.commit('setModelResponse',
  34. { model: models.serverConfig, data: humps.camelizeKeys(window.CONFIG) });
  35. };
  36. document.body.appendChild(s);
  37. },
  38. },
  39. });
  40. // window.CONFIG is loaded from /api/config.js directly in a <script> tag.
  41. if (window.CONFIG) {
  42. store.commit('setModelResponse',
  43. { model: models.serverConfig, data: humps.camelizeKeys(window.CONFIG) });
  44. // Load language.
  45. i18n.locale = window.CONFIG.lang['_.code'];
  46. i18n.setLocaleMessage(i18n.locale, window.CONFIG.lang);
  47. }
  48. new Vue({
  49. router,
  50. store,
  51. i18n,
  52. render: (h) => h(App),
  53. }).$mount('#app');