diff --git a/frontend/src/store/modules/user.js b/frontend/src/store/modules/user.js index 3febd8a062..e67c16c1d3 100644 --- a/frontend/src/store/modules/user.js +++ b/frontend/src/store/modules/user.js @@ -5,6 +5,7 @@ import { format } from '@/utils/formatUi' import { getLanguage } from '@/lang/index' import Cookies from 'js-cookie' import router from '@/router' +import i18n from '@/lang' const getDefaultState = () => { return { token: getToken(), @@ -57,6 +58,9 @@ const mutations = { SET_LANGUAGE: (state, language) => { state.language = language Cookies.set('language', language) + if (language && i18n.locale !== language) { + i18n.locale = language + } } } diff --git a/frontend/src/utils/request.js b/frontend/src/utils/request.js index 8bdc5387fd..1133e95334 100644 --- a/frontend/src/utils/request.js +++ b/frontend/src/utils/request.js @@ -36,7 +36,8 @@ service.interceptors.request.use( } if (i18n.locale) { - config.headers['Accept-Language'] = i18n.locale + const lang = i18n.locale.replace('_', '-') + config.headers['Accept-Language'] = lang } // 增加loading