unibest/src/pages/index/i18n.vue

52 lines
1.1 KiB
Vue
Raw Normal View History

<route lang="json">
{
"style": {
"navigationBarTitleText": "%app.name%"
}
}
</route>
2024-01-29 18:59:17 +08:00
2024-01-29 19:14:01 +08:00
<template>
<view>{{ $t('app.name') }}</view>
<view>切换语言 </view>
<view class="uni-list">
<radio-group @change="radioChange">
<label class="uni-list-cell uni-list-cell-pd" v-for="item in languages" :key="item.value">
<view>
<radio :value="item.value" :checked="item.value === current" />
</view>
<view>{{ item.name }}</view>
</label>
</radio-group>
</view>
<!-- http://localhost:9000/#/pages/index/i18n -->
<button @click="testI18n">测试弹窗</button>
</template>
2024-01-29 18:59:17 +08:00
<script lang="ts" setup>
2024-01-29 19:14:01 +08:00
import { getLocale } from '@/locales/index'
2024-01-29 18:59:17 +08:00
import { testI18n } from '@/utils/index'
2024-01-29 19:14:01 +08:00
const current = ref(getLocale())
const languages = [
{
value: 'zh',
name: '中文',
checked: 'true',
},
{
value: 'en',
name: '英文',
},
]
const radioChange = (evt) => {
// console.log(evt)
current.value = evt.detail.value
// https://uniapp.dcloud.net.cn/api/ui/locale.html#setlocale
uni.setLocale(evt.detail.value)
}
2024-01-29 18:59:17 +08:00
</script>