fix: 解决国际化刷新丢失问题以及pinia缓存失效问题
This commit is contained in:
parent
612d9b1e6c
commit
1f080e7e0a
@ -1,11 +1,16 @@
|
||||
import { createI18n } from "vue-i18n";
|
||||
import zhCN from "@/lang/modules/zhCN";
|
||||
import enUS from "@/lang/modules/enUS";
|
||||
// import pinia from "@/store/index";
|
||||
// import { storeToRefs } from "pinia";
|
||||
// import { useThemeConfig } from "@/store/modules/theme-config";
|
||||
// const themeStore = useThemeConfig(pinia);
|
||||
// const { language } = storeToRefs(themeStore);
|
||||
|
||||
/* 获取语言 */
|
||||
const getLang = () => {
|
||||
let store = localStorage.getItem("theme-config");
|
||||
if (store) {
|
||||
return JSON.parse(store)?.language || "zh-CN";
|
||||
} else {
|
||||
return "zh-CN";
|
||||
}
|
||||
};
|
||||
/* 这里必须是messages名称 */
|
||||
const messages = {
|
||||
"zh-CN": zhCN,
|
||||
@ -15,7 +20,7 @@ const messages = {
|
||||
const i18n = createI18n({
|
||||
legacy: false, // Composition API模式需要设为false
|
||||
globalInjection: true, // 全局生效: $
|
||||
locale: "zh-CN", // 默认语言
|
||||
locale: getLang(), // 默认语言
|
||||
messages // 数据源
|
||||
});
|
||||
|
||||
|
||||
@ -20,7 +20,7 @@ export default {
|
||||
["about-project"]: "about project",
|
||||
["not-power"]: "No permission",
|
||||
["not-found"]: "Page not found",
|
||||
["zh-CN"]: "Chinese",
|
||||
["zh-CN"]: "中文",
|
||||
["en-US"]: "English",
|
||||
["refresh"]: "refresh",
|
||||
["close-current"]: "close current",
|
||||
|
||||
@ -128,9 +128,9 @@ const onLange = (e: string) => {
|
||||
themeStore.setLanguage("en-US");
|
||||
}
|
||||
i18n.locale.value = language.value;
|
||||
console.log("国际化", language.value);
|
||||
};
|
||||
|
||||
// 退出登录
|
||||
const logOut = () => {
|
||||
Modal.warning({
|
||||
title: "提示",
|
||||
|
||||
@ -122,7 +122,7 @@ const onSubmit = ({ errors }: any) => {
|
||||
stores.setAccount(account);
|
||||
stores.setToken("DC-Admin");
|
||||
Message.success("登录成功");
|
||||
router.push("/home");
|
||||
router.replace("/home");
|
||||
};
|
||||
</script>
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user