头部导航添加中英文切换按钮功能
This commit is contained in:
parent
2b76024175
commit
748709d402
BIN
assets/image/icon/language.png
Normal file
BIN
assets/image/icon/language.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.6 KiB |
@ -16,6 +16,9 @@
|
|||||||
@keydown.enter="search"
|
@keydown.enter="search"
|
||||||
>
|
>
|
||||||
</b-form-input>
|
</b-form-input>
|
||||||
|
<nuxt-link :to="`/?lang=${$store.state.locale === 'en' ? 'zh' : 'en'}`" target="_blank">
|
||||||
|
<img class="ml-3" width="20px" src="~assets//image/icon/language.png" :alt="$t('common.language')" />
|
||||||
|
</nuxt-link>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
@ -37,6 +40,9 @@
|
|||||||
:alt="$t('common.menu')"
|
:alt="$t('common.menu')"
|
||||||
@click="$refs.menuDrawerRef.drawer=true"
|
@click="$refs.menuDrawerRef.drawer=true"
|
||||||
/>
|
/>
|
||||||
|
<nuxt-link :to="`/?lang=${$store.state.locale === 'en' ? 'zh' : 'en'}`" target="_blank">
|
||||||
|
<img class="ml-3" width="20px" src="~assets//image/icon/language.png" :alt="$t('common.language')" />
|
||||||
|
</nuxt-link>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@ -31,7 +31,8 @@
|
|||||||
"next": "Next",
|
"next": "Next",
|
||||||
"prev": "Prev",
|
"prev": "Prev",
|
||||||
"submitSuccess": "Submit success",
|
"submitSuccess": "Submit success",
|
||||||
"fulltextsearch": "Full text search"
|
"fulltextsearch": "Full text search",
|
||||||
|
"language": "Language"
|
||||||
},
|
},
|
||||||
"menu": {
|
"menu": {
|
||||||
"Home": "Home",
|
"Home": "Home",
|
||||||
|
|||||||
@ -31,7 +31,8 @@
|
|||||||
"next": "下一个",
|
"next": "下一个",
|
||||||
"prev": "上一个",
|
"prev": "上一个",
|
||||||
"submitSuccess": "提交成功",
|
"submitSuccess": "提交成功",
|
||||||
"fulltextsearch": "全站搜索"
|
"fulltextsearch": "全站搜索",
|
||||||
|
"language": "语言"
|
||||||
},
|
},
|
||||||
"menu": {
|
"menu": {
|
||||||
"Home": "首页",
|
"Home": "首页",
|
||||||
|
|||||||
@ -4,10 +4,11 @@ export default function ({
|
|||||||
store,
|
store,
|
||||||
route,
|
route,
|
||||||
query,
|
query,
|
||||||
|
$cookies,
|
||||||
error,
|
error,
|
||||||
redirect
|
redirect
|
||||||
}) {
|
}) {
|
||||||
const defaultLocale = app.i18n.fallbackLocale
|
const defaultLocale = $cookies.get('lang') || app.i18n.fallbackLocale
|
||||||
if (isHMR) {
|
if (isHMR) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -15,6 +16,7 @@ export default function ({
|
|||||||
if (!store.state.locales.includes(locale)) {
|
if (!store.state.locales.includes(locale)) {
|
||||||
return error({ message: 'This page could not be found.', statusCode: 404 })
|
return error({ message: 'This page could not be found.', statusCode: 404 })
|
||||||
}
|
}
|
||||||
|
|
||||||
store.commit('SET_LANG', locale)
|
store.commit('SET_LANG', locale)
|
||||||
app.i18n.locale = store.state.locale
|
app.i18n.locale = store.state.locale
|
||||||
|
|
||||||
|
|||||||
@ -16,6 +16,7 @@ export const mutations = {
|
|||||||
SET_LANG (state, locale) {
|
SET_LANG (state, locale) {
|
||||||
if (state.locales.includes(locale)) {
|
if (state.locales.includes(locale)) {
|
||||||
state.locale = locale
|
state.locale = locale
|
||||||
|
this.$cookies.set('lang', locale)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
SET_FOOTER_INFO (state, info) {
|
SET_FOOTER_INFO (state, info) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user