fix: 解决国际化刷新丢失问题以及pinia缓存失效问题

This commit is contained in:
wf 2024-04-29 11:47:02 +08:00
parent 612d9b1e6c
commit 1f080e7e0a
4 changed files with 14 additions and 9 deletions

View File

@ -1,11 +1,16 @@
import { createI18n } from "vue-i18n"; import { createI18n } from "vue-i18n";
import zhCN from "@/lang/modules/zhCN"; import zhCN from "@/lang/modules/zhCN";
import enUS from "@/lang/modules/enUS"; import enUS from "@/lang/modules/enUS";
// import pinia from "@/store/index";
// import { storeToRefs } from "pinia"; /* 获取语言 */
// import { useThemeConfig } from "@/store/modules/theme-config"; const getLang = () => {
// const themeStore = useThemeConfig(pinia); let store = localStorage.getItem("theme-config");
// const { language } = storeToRefs(themeStore); if (store) {
return JSON.parse(store)?.language || "zh-CN";
} else {
return "zh-CN";
}
};
/* 这里必须是messages名称 */ /* 这里必须是messages名称 */
const messages = { const messages = {
"zh-CN": zhCN, "zh-CN": zhCN,
@ -15,7 +20,7 @@ const messages = {
const i18n = createI18n({ const i18n = createI18n({
legacy: false, // Composition API模式需要设为false legacy: false, // Composition API模式需要设为false
globalInjection: true, // 全局生效: $ globalInjection: true, // 全局生效: $
locale: "zh-CN", // 默认语言 locale: getLang(), // 默认语言
messages // 数据源 messages // 数据源
}); });

View File

@ -20,7 +20,7 @@ export default {
["about-project"]: "about project", ["about-project"]: "about project",
["not-power"]: "No permission", ["not-power"]: "No permission",
["not-found"]: "Page not found", ["not-found"]: "Page not found",
["zh-CN"]: "Chinese", ["zh-CN"]: "中文",
["en-US"]: "English", ["en-US"]: "English",
["refresh"]: "refresh", ["refresh"]: "refresh",
["close-current"]: "close current", ["close-current"]: "close current",

View File

@ -128,9 +128,9 @@ const onLange = (e: string) => {
themeStore.setLanguage("en-US"); themeStore.setLanguage("en-US");
} }
i18n.locale.value = language.value; i18n.locale.value = language.value;
console.log("国际化", language.value);
}; };
// 退
const logOut = () => { const logOut = () => {
Modal.warning({ Modal.warning({
title: "提示", title: "提示",

View File

@ -122,7 +122,7 @@ const onSubmit = ({ errors }: any) => {
stores.setAccount(account); stores.setAccount(account);
stores.setToken("DC-Admin"); stores.setToken("DC-Admin");
Message.success("登录成功"); Message.success("登录成功");
router.push("/home"); router.replace("/home");
}; };
</script> </script>