main.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 { watch } from "vue";
  11. import vT from './directives/v-t'
  12. export const i18n = createI18n({
  13. legacy: false,
  14. allowComposition: true,
  15. locale: lang.value || "cn",
  16. messages,
  17. });
  18. globalThis.__i18n = i18n
  19. const pinia = createPinia();
  20. // #ifdef VUE3
  21. import { createSSRApp } from "vue";
  22. export function createApp() {
  23. const app = createSSRApp(App);
  24. app.directive('ellipsis', vEllipsis);
  25. app.use(uviewPlus);
  26. app.use(pinia);
  27. app.use(i18n);
  28. app.directive('t', vT);
  29. // 保持 locale 与存储 lang 同步(可选)
  30. watch(() => lang.value, (val) => {
  31. if (!val) return;
  32. if (i18n?.global?.locale?.value !== undefined) {
  33. i18n.global.locale.value = val;
  34. }
  35. }, { immediate: true, flush: 'sync' });
  36. routeInterceptor.install();
  37. return { app };
  38. }
  39. // #endif