江麻妞
2021-06-01 eca8907a11c28d816c3da5a0667f45a38a499012
fix: Fix the problem that the `lang` attribute of `HTML` will not be set when it is first loaded (#682)

* refactor: Encapsulate the function of changing the page language

* fix(lang): Fix the problem that the `lang` attribute of `HTML` will not be set when it is first loaded
2个文件已修改
11 ■■■■ 已修改文件
src/locales/setupI18n.ts 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/locales/useLocale.ts 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/locales/setupI18n.ts
@@ -3,7 +3,7 @@
import { createI18n } from 'vue-i18n';
import { setLoadLocalePool } from './useLocale';
import { setLoadLocalePool, setHtmlPageLang } from './useLocale';
import { localeSetting } from '/@/settings/localeSetting';
import { useLocaleStoreWithOut } from '/@/store/modules/locale';
@@ -16,7 +16,8 @@
  const locale = localeStore.getLocale;
  const defaultLocal = await import(`./lang/${locale}.ts`);
  const message = defaultLocal.default?.message ?? {};
  setHtmlPageLang(locale)
  setLoadLocalePool((loadLocalePool) => {
    loadLocalePool.push(locale);
  });
src/locales/useLocale.ts
@@ -17,6 +17,10 @@
const loadLocalePool: LocaleType[] = [];
export function setHtmlPageLang(locale: LocaleType) {
  document.querySelector('html')?.setAttribute('lang', locale);
}
export function setLoadLocalePool(cb: (loadLocalePool: LocaleType[]) => void) {
  cb(loadLocalePool);
}
@@ -30,7 +34,7 @@
    (i18n.global.locale as any).value = locale;
  }
  localeStore.setLocaleInfo({ locale });
  document.querySelector('html')?.setAttribute('lang', locale);
  setHtmlPageLang(locale)
}
export function useLocale() {