LangSwitch.vue 665 B

123456789101112131415161718192021222324252627282930
  1. <template>
  2. <div class="lang-switch">
  3. <el-button @click="switchToZh" :type="langStore.currentLang === 'zh-CN' ? 'primary' : 'text'">中文</el-button>
  4. <el-button @click="switchToEn" :type="langStore.currentLang === 'en' ? 'primary' : 'text'">English</el-button>
  5. </div>
  6. </template>
  7. <script setup>
  8. import { useLangStore } from '@/pinia/langStore'
  9. const langStore = useLangStore()
  10. // 切换到中文
  11. const switchToZh = () => {
  12. langStore.changeLang('zh-CN')
  13. }
  14. // 切换到英文
  15. const switchToEn = () => {
  16. langStore.changeLang('en')
  17. }
  18. </script>
  19. <style scoped>
  20. .lang-switch button {
  21. margin: 0 8px;
  22. padding: 4px 12px;
  23. cursor: pointer;
  24. }
  25. </style>