index.vue 921 B

1234567891011121314151617181920212223242526272829303132
  1. <template>
  2. <el-dropdown class="vab-language" @command="handleCommand">
  3. <vab-icon icon="translate-2" />
  4. <template #dropdown>
  5. <el-dropdown-menu>
  6. <el-dropdown-item command="zh">中文简体</el-dropdown-item>
  7. <el-dropdown-item command="en">English</el-dropdown-item>
  8. </el-dropdown-menu>
  9. </template>
  10. </el-dropdown>
  11. </template>
  12. <script lang="ts" setup>
  13. import { useSettingsStore } from '/@/store/modules/settings'
  14. import getPageTitle from '/@/utils/pageTitle'
  15. defineOptions({
  16. name: 'VabLanguage',
  17. })
  18. const { locale } = useI18n()
  19. const route = useRoute()
  20. const settingsStore = useSettingsStore()
  21. const { changeLanguage } = settingsStore
  22. const handleCommand = (language: string) => {
  23. changeLanguage(language)
  24. locale.value = language
  25. document.title = getPageTitle(route.meta.title)
  26. if (route.path === '/login' || route.path === '/register') location.reload()
  27. }
  28. </script>