main.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import App from "./App";
  2. import uviewPlus from "uview-plus";
  3. import { createPinia } from "pinia";
  4. import { messages } from "./locale/index";
  5. import { interpolateTemplate } from "./locale/utils";
  6. import vEllipsis from './directives/v-ellipsis'
  7. import { createI18n } from "vue-i18n";
  8. import { routeInterceptor } from '@/utils/routeInterceptor.js'
  9. import { lang } from '@/composables/config'
  10. // import './static/js/jsvm_all.js'
  11. import { watch } from "vue";
  12. import vT from './directives/v-t'
  13. export const i18n = createI18n({
  14. legacy: false,
  15. allowComposition: true,
  16. locale: lang.value || "cn",
  17. messages,
  18. });
  19. globalThis.__i18n = i18n
  20. const pinia = createPinia();
  21. // #ifdef VUE3
  22. import { createSSRApp } from "vue";
  23. export function createApp() {
  24. const app = createSSRApp(App);
  25. app.directive('ellipsis', vEllipsis);
  26. app.use(uviewPlus);
  27. app.use(pinia);
  28. app.use(i18n);
  29. app.directive('t', vT);
  30. // 保持 locale 与存储 lang 同步(可选)
  31. watch(() => lang.value, (val) => {
  32. if (!val) return;
  33. if (i18n?.global?.locale?.value !== undefined) {
  34. i18n.global.locale.value = val;
  35. }
  36. }, { immediate: true, flush: 'sync' });
  37. routeInterceptor.install();
  38. return { app };
  39. }
  40. // #endif