likes
comments
collection
share

vue3国际化语言包在js文件中的使用

作者站长头像
站长
· 阅读数 30

main.tsapp.use(i18n)

js中使用

<script setup lang="ts">
import { getCurrentInstance, ComponentInternalInstance } from "vue"

const { appContext } = getCurrentInstance() as ComponentInternalInstance

let msg = appContext.config.globalProperties.$t("message")
console.log(msg)
</script>

模板中使用

<div>{{$t('message')}}</div>

<el-input v-model="value" :placeholder="$t('inputPlaceholder')" />