feat: save lang to localStorage

This commit is contained in:
qier222 2020-10-22 18:13:48 +08:00
parent 91fac552e0
commit 281f9fe0bc
5 changed files with 67 additions and 50 deletions

View file

@ -9,18 +9,18 @@
/></button-icon>
</div>
<div class="navigation-links">
<router-link to="/" :class="{ active: this.$route.name === 'home' }"
>{{ $t('nav.home') }}</router-link
>
<router-link to="/" :class="{ active: this.$route.name === 'home' }">{{
$t("nav.home")
}}</router-link>
<router-link
to="/explore"
:class="{ active: this.$route.name === 'explore' }"
>{{ $t('nav.explore') }}</router-link
>{{ $t("nav.explore") }}</router-link
>
<router-link
to="/library"
:class="{ active: this.$route.name === 'library' }"
>{{ $t('nav.library') }}</router-link
>{{ $t("nav.library") }}</router-link
>
</div>
<div class="right-part">
@ -42,8 +42,7 @@
</div>
</div>
<div class="locale-changer" @click="changeLang">
<svg-icon icon-class="translation" class="translation"
/>
<svg-icon icon-class="translation" class="translation" />
</div>
</div>
</nav>
@ -55,13 +54,13 @@ import ButtonIcon from "@/components/ButtonIcon.vue";
export default {
name: "Navbar",
components: {
ButtonIcon,
ButtonIcon
},
data() {
return {
inputFocus: false,
keywords: "",
langs: ['zh-CN', 'en']
langs: ["zh-CN", "en"]
};
},
methods: {
@ -71,19 +70,27 @@ export default {
},
goToSearchPage() {
if (!this.keywords) return;
if (this.$route.name === 'search' && this.$route.query.keywords === this.keywords) return;
if (
this.$route.name === "search" &&
this.$route.query.keywords === this.keywords
)
return;
this.$router.push({
name: "search",
query: { keywords: this.keywords },
query: { keywords: this.keywords }
});
},
changeLang() {
let lang = "";
if (this.$i18n.locale === "zh-CN") {
return this.$i18n.locale = "en";
lang = "en";
} else {
lang = "zh-CN";
}
this.$i18n.locale = "zh-CN";
this.$i18n.locale = lang;
this.$store.commit("changeLang", lang);
}
},
}
};
</script>
@ -215,6 +222,4 @@ nav {
width: 48px;
}
}
</style>