switchLanguage.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <template>
  2. <view class="page">
  3. <view class="btn-list">
  4. <view class="language" data-lang="zh-CN" @tap="langChange"> <text>简体中文</text>
  5. <image v-if="languageSelect=='zh-CN'" class="selected" src="../../static/mine/326.png" mode=""></image>
  6. </view>
  7. <view class="language" data-lang="en-US" @tap="langChange"> <text>English</text>
  8. <image v-if="languageSelect=='en-US'" class="selected" src="../../static/mine/326.png" mode=""></image>
  9. </view>
  10. <view class="language" data-lang="es-ES" @tap="langChange"> <text>Español</text>
  11. <image v-if="languageSelect=='es-ES'" class="selected" src="../../static/mine/326.png" mode=""></image>
  12. </view>
  13. <view class="language" data-lang="it-IT" @tap="langChange"> <text>Italiano</text>
  14. <image v-if="languageSelect=='it-IT'" class="selected" src="../../static/mine/326.png" mode=""></image>
  15. </view>
  16. </view>
  17. </view>
  18. </template>
  19. <script>
  20. export default {
  21. data() {
  22. return {
  23. languageSelect: ''
  24. }
  25. },
  26. computed: {
  27. i18n() {
  28. return this.$t('index')
  29. }
  30. },
  31. methods: {
  32. langChange(e) {
  33. const {
  34. lang
  35. } = e.currentTarget.dataset
  36. uni.setStorageSync("language", lang)
  37. this._i18n.locale = lang
  38. this.languageSelect = lang
  39. uni.setNavigationBarTitle({
  40. title: this.i18n.switchLanguage
  41. })
  42. }
  43. },
  44. created() {
  45. this.languageSelect = this._i18n.locale
  46. uni.setNavigationBarTitle({
  47. title: this.i18n.switchLanguage
  48. })
  49. }
  50. }
  51. </script>
  52. <style scoped lang="scss">
  53. .page {
  54. padding: 20rpx 24rpx;
  55. .btn-list {
  56. background-color: #fff;
  57. border-radius: 16rpx;
  58. padding: 0 20rpx;
  59. .language {
  60. display: flex;
  61. align-items: center;
  62. justify-content: space-between;
  63. height: 110rpx;
  64. border-bottom: 2rpx solid rgba(151, 151, 151, 0.2);
  65. .selected {
  66. width: 36rpx;
  67. height: 36rpx;
  68. }
  69. }
  70. }
  71. }
  72. </style>