BaseLang.vue 778 B

1234567891011121314151617181920212223242526272829303132
  1. <script setup lang="ts">
  2. const { locale, setLocale } = useI18n();
  3. const activeLangKey = ref(unref(locale));
  4. const changeLanguage = (lang: 'zh' | 'en') => {
  5. activeLangKey.value = lang;
  6. setLocale(lang);
  7. }
  8. </script>
  9. <template>
  10. <div class="lang-switch">
  11. <span :class="{ active: activeLangKey === 'zh' }" @click="changeLanguage('zh')">中</span>
  12. <span class="active px-[5px]"> / </span>
  13. <span :class="{ active: activeLangKey === 'en' }" @click="changeLanguage('en')" style="cursor: not-allowed;">En</span>
  14. </div>
  15. </template>
  16. <style scoped lang="scss">
  17. .lang-switch {
  18. font-size: 14px;
  19. color: rgba(22, 22, 22, 0.5);
  20. &:nth-child(1), &:nth-child(3) {
  21. cursor: pointer;
  22. }
  23. .active {
  24. color: #161616;
  25. }
  26. }
  27. </style>